// RichTextKit
// Copyright © 2019-2020 Topten Software. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this product except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Topten.RichTextKit.Utils;
namespace Topten.RichTextKit
{
///
/// Represets a style run - a logical run of characters all with the same
/// style.
///
public class StyleRun : IRun
{
///
/// Get the code points of this run.
///
public Slice CodePoints => CodePointBuffer.SubSlice(Start, Length);
///
/// Get the text of this style run
///
/// A string
public override string ToString()
{
return Utf32Utils.FromUtf32(CodePoints);
}
///
/// The index of the first code point in this run (relative to the text block
/// as a whole).
///
public int Start
{
get;
internal set;
}
///
/// The number of code points this run.
///
public int Length
{
get;
internal set;
}
///
/// The index of the first code point after this run.
///
public int End => Start + Length;
///
/// The style attributes to be applied to text in this run.
///
public IStyle Style
{
get;
internal set;
}
int IRun.Offset => Start;
int IRun.Length => Length;
///
/// The global list of code points
///
internal Buffer CodePointBuffer;
internal static ThreadLocal> Pool = new ThreadLocal>(() => new ObjectPool()
{
Cleaner = (r) =>
{
r.CodePointBuffer = null;
r.Style = null;
}
});
}
}