Using Candera TextEngine to draw Text
説明Description
The simplest way to draw text with Canderaでテキストを描画する最も簡単な方法は、TextNode2D、 is using a TextNode2D, a 3D text widget from CGI Studio Widget LibraryLibrary, のor 3D テキスト ウィジェット、またはthe 2D TextBrush 効果を使用することです。参照する:effect. Refer to:
To learn about how to use Candera::TextNode2Dの使用方法については、次のセクションを参照してください。, please refer to the following section:
To learn about details, how to use the Candera TextEngine インターフェイスを直接使用する方法の詳細については、次の章を参照してください。interface directly, refer to the following chapters.
章Chapters
Using Candera::TextNode2Dの使用
章Chapters
概要Overview
TextNode2D は、高速テキストrepresents レンダリングに特化したa RenderNode を表します。specialized for fast text rendering.
テキストとスタイルを提供する必要があります。さらに、レンダリング用のText and style have to be provided. In addition, it requires a BitmapBrush 効果と、関連付けられたeffect for rendering and a Candera::TextNodeRenderer object used for generating the images, which will be then rendered by the associated BitmapBrush 効果によってレンダリングされる画像の生成に使用されるCandera::TextNodeRendererオブジェクトが必要です。effect.
There are four Candera::TextNodeRenderer の4implementations つの実装が利用可能で、それぞれが既存のavailable, each corresponding to one CacheType option from the existing Candera::TextBrushレンダリング コンセプトrendering concept (ビットマップ、サーフェス、グリフ、およびグリフBitmap, キャッシュ)Surface, のGlyph 1and つのGlyph CacheType オプションに対応しています。Cache).
Text layouting is supported by attaching a テキストのレイアウトは、 Candera::TextNode2DLayouter をノードにアタッチすることでサポートされます。to the node. It is responsible for arranging and truncating the associated text of a Candera::TextNode2Dの関連テキストの配置と切り詰めを担当します。デフォルトのレイアウタは、水平方向と垂直方向の両方の切り捨てを実装しています。. The default layouter implements both horizontal and vertical truncation.
Candera::TextNodeRendererオブジェクトは、提供されたテキストから正しい画像を生成するために使用されます。 object is used for generating the correct images from provided text.
The level cache strategies which apply for a Candera::TextNode2Dに適用されるレベル キャッシュ戦略を以下に説明します。are described below:
ビットマップ:Bitmap:非常に大きなメモリveryフットプリント、非常に長い更新時間、短いレンダリング時間large memory footprint, very large update times, small render time- Surface:
大きなビデオlargeメモリvideoフットプリント、長い更新時間、短いレンダリング時間memory footprint, large update times, small render time - Glyph (
以前のformer NoCache):メモリsmallフットプリントが小さく、更新時間が短く、レンダリング時間が非常に長い。memory footprint, small update times, very large render time. - GlyphCache:
小さいメモリsmallフットプリント、短い更新時間、中程度のレンダリング時間memory footprint, small update times, medium render time - GlyphAtlas:
小さなsmall (しかしグローバルな)butビデオglobal)メモリvideoフットプリント、短い更新時間、短いレンダリング時間。memory footprint, small update times, small render time.
-
パフォーマンスのバランスを取るために適切なキャッシュを選択してください。静的テキストを使用する場合はビットマップまたはサーフェスChooseレンダリングtheタイプを使用することをお勧めしますが、動的テキストの場合はappropriate cache for a balance in performance. It is recommended to use either Bitmap or Surface rendering type when static texts are used, while for dynamic texts, GlyphCacheを使用することをお勧めします。is recommended.
Please consider that only BitmapBrush type effects apply to a Candera::TextNode2Dには. In case other effects are used nothing will be rendered. The text appearance can be altered by the type of effect chosen, either by modifying the in-place effects (color, mask, HSL transformations, etc.) or by changing blending effects.
List of BitmapBrush タイプのエフェクトのみが適用されることを考慮してください。他の効果が使用されている場合、何もレンダリングされません。テキストの外観は、インプレース効果effects (色、マスク、HSLwhich 変換など)can を変更するか、ブレンド効果を変更することによって、選択した効果の種類によって変更できます。
使用できるused BitmapBrushare 効果のリストを以下に示します。described below:
- Candera::BitmapBrushBlend
:ビットマップOutputsイメージを出力し、ストアaバッファーとブレンドします。bitmap image, and blend it with the store buffer. - Candera::BitmapBrushColorBlend
:ビットマップOutputイメージを出力し、色を調整して、ストアaバッファーとブレンドします。bitmap image, modulate the color, and blend it with the store buffer. - Candera::BitmapBrushColorMaskBlend
:ビットマップOutputイメージを出力し、色を調整し、アルファaマスクを適用して、ストアbitmapバッファーとブレンドします。image, modulate the color, apply an alpha mask, and blend it with the store buffer. - Candera::BitmapBrushHslBlend
:ビットマップOutputイメージを出力し、a bitmap image, apply a HSL変換を適用して、ストアtransformation,バッファーとブレンドします。and blend it with the store buffer. - Candera::BitmapBrushMaskBlend
:ビットマップOutputイメージを出力し、アルファaマスクを適用して、ストアbitmapバッファーとブレンドします。image, apply an alpha mask, and blend it with the store buffer. - Candera::BlurBitmapBrushBlend
:ぼかしとアルファOutputブレンドのビットマップaイメージを出力します。blurred and alpha blended bitmap image. - Candera::MirrorBitmapBrushBlend
:出力にはビットマップOutputイメージとその反射が含まれます。includes the bitmap image and it's reflection. - Candera::ShadowBitmapBrushBlend
:シャドウ/グローとイメージOutputアルファaブレンドの両方で、シャドウまたはグローshadowedビットマップorイメージを出力します。glowing bitmap image, both shadow/glow and image alpha blended. - Candera::ShearBitmapBrushBlend
:元の画像からせん断された画像を出力します。Output a sheared image from the original one.
-
すべてのNot all BitmapBrush効果でeffects have the Colorプロパティを使用できるわけではありません。property available. Default color for a TextNode2Dのデフォルトの色は白です。is white.
Candera::TextNode2DLayouter は、is responsible for arranging and truncating the text associated to a Candera::TextNode2Dに関連付けられたテキストの配置と切り詰めを担当します。Candera:: TextNode2DLayouter から派生した. Candera::DefaultTextNode2DLayouter, derived from Candera::TextNode2DLayouter, DefaultTextNode2DLayouterは、テキストの切り捨てに使用されます。詳細については、次のセクションで説明します。is used for text truncation. More details are provided in the following section.
Candera::TextNode2D ガイドラインGuidelines
The minimum necessary steps needed in order to render a TextNode2D をレンダリングするために最低限必要な手順は次のとおりです。are:
- Create a TextNode2D
インスタンスを作成するinstance - Set a Text:
レンダリングするテキストを設定します。Text to be rendered. レンダリングに使用するSet a Style: Styleオブジェクトを設定します。object to be used for rendering.TextNodeRendererDefineを定義します:a TextNodeRenderer: TextNodeRendererは、提供されたテキストから正しい画像を生成するために使用されます。used for generating the correct images from provided text.BitmapBrushAttach効果のアタッチ: 関連するa BitmapBrush効果は、生成された画像のレンダリングを担当します。effect: The associated BitmapBrush effect is responsible for rendering the generated images.
ノードと効果を定義するDefine node and effect
Define a Candera::TextNode2Dと関連する and the associated BitmapBrush 効果を定義します。effect:
TextNode2D* m_textNode;
BitmapBrushColorBlend::SharedPointer m_textNodeEffect;
ノードとエフェクトを作成するCreate node and effect
Create an instance of Candera::TextNode2D class by using Candera::TextNode2D::Create()メソッドを使用して、Candera::TextNode2D クラスのインスタンスを作成します。method:
m_textNode = TextNode2D::Create();
同様の方法でIn similar way create the BitmapBrush 効果を作成し、この効果を新しく作成したeffect and add this effect to the newly created Candera::TextNode2Dに追加します。:
m_textNodeEffect = BitmapBrushColorBlend::Create(); m_textNode->AddEffect(m_textNodeEffect.GetPointerToSharedInstance());
Use Candera::TextNode2D::SetText()を使用して、レンダリングするテキストを指定します。 to specify the text to be rendered:
Use Candera::TextNode2D::SetStyle()を使用してスタイル オブジェクトを指定します。to specify the style object:
m_textNode->SetText("TextNode2D");
Create and set a Candera::TextNodeRenderer to Candera::TextNode2D using Candera::TextNode2D::SetTextNodeRenderer()メソッドを使用して、Candera::TextNodeRendererを作成し、 Candera::TextNode2Dに設定します。method:
m_textNode->SetTextNodeRenderer(&GlyphCacheTextNodeRenderer::GetInstance());
最後に、Finally, add the textNode をdirectly to a Candera::Scene2Dまたは or a Candera::Group2Dに直接追加します。:
m_textNodeGroup->AddChild(m_textNode);
Candera::TextNode2D プロパティProperties
Changing the color of a Candera::TextNode2Dの色の変更は、関連する is done through the associated BitmapBrush 効果によって行われます。エフェクトの使用によっては、すべてのeffect. Depending on the effect use, not all BitmapBrush エフェクトがカラーeffects プロパティを公開するわけではありません。この場合、レンダリングされたテキストは白になります。expose a color property. In this case, the rendered text will be white.
m_textNodeEffect->GetColorEffect().Color().Set(Color(0.0f, 0.0f, 0.0f, 1.0f));
Text alignment is realized through the layouter properties of the テキストの配置は、 Candera::TextNode2Dのレイアウター, プロパティによって実現されます。つまり、レイアウター内の位置とmeaning Canderathat the position inside a layouter, as well as text position inside the :Candera::TextNode2D内のテキストの位置は、同じ will now be changed by the same Candera::TextNode2DLayouter::SetHorizontalAlignment(SetHorizontalAlignment() によって変更されます。and Candera::TextNode2DLayouter::SetHorizontalAlignment(SetHorizontalAlignment() メソッドはレイアウタです。methods the layouter. In case it in necessary to have a different text position than the provided layouting options, it is possible to nest 提供されたレイアウト オプションとは異なるテキスト位置が必要な場合は、 Candera::TextNode2Dをネストして、内側の TextNodeand に異なる配置値を設定することができます。set different alignment values for the inner TextNode.
TextNode2DLayouter::SetHorizontalAlignment(*m_textNode, Candera::HLeft);
TextNode2DLayouter::SetVerticalAlignment(*m_textNode, Candera::VTop);
Candera::TextNode2D が提供する切り捨てタイプはprovides 1only つだけです。切り捨てが必要な場合、テキストは切り取られ、スペースに合わせて末尾の省略記号が追加されます。デフォルトでは、切り捨てはサポートされていません。このためには、one truncation type - in case truncation is needed, the text gets cut and trailing ellipsis are added to fit the space. Truncation is not supported by default. For this, the Candera::DefaultTextNode2DLayouter をCandera:needs to be attached to にアタッチする必要があり(以下のスニペットを参照)、テキストのサイズがCandera::TextNode2Dの指定された (see snippet below) and the text will be automatically truncated whenever the size of the text no longer fits in the specified Layout Sizeプロパティに収まらなくなると、テキストは自動的に切り捨てられます。テキストの切り捨てを実行するとき、境界四角形のサイズは考慮されません。 property of Candera::TextNode2D. Bounding rectangle size is not taken in account when performing text truncations.
m_textNode->SetLayouter(&TextNode2DLayouter::GetDefault());
TextNode2DMultiline では、複数行のレイアウトがデフォルトで有効になっています。このプロパティは、layouting is enabled by default for a TextNode2D. This property can be enabled/disabled using Candera::TextNode2DLayouter::SetMultiLineEnabled() メソッドを使用して有効/無効にすることができます。method.
TextNode2D では、Wordwrap はデフォルトでは有効になっていません。このプロパティは、is not enabled by default for a TextNode2D. This property can be enabled/disabled using Candera::TextNode2DLayouter::SetWordWrapEnabled() メソッドを使用して有効/無効にすることができます。method.
グリフGlyph ベースの高さの計算は引き続き行われますが、レイアウトには使用されません。based height computation is still done, but it is not used for layouting. The rectangle in which the text is layouted, if Size がis (-1;-1), の場合、テキストが配置される四角形は、古いwill be the one measured with old TextBrushConstantHeight オプションで測定されたものになります。option. The TextBrushActualHeight は、ノードの境界矩形を取得するために常に使用されますが、ノードのレイアウト矩形を取得することもできますis always used for retrieving the bounding rectangle of the node, but it is also possible to retrieve the layout rectangle of the node too (以下のテキスト長の計算に関する情報を参照してください)。see information about text length calculation below).
レンダリングされたテキストのサイズを取得するために、次のメソッドが提供されています。The following methods are provided for retrieving the size of the rendered text:
レイアウトGettingテキストtheボックスの取得layouting text box (一定の高さ、カーソルからカーソルへの左から右への測定)measured with constant height, cursor to cursor from left to right):境界テキストGettingボックスの取得the bounding text box (グリフの垂直方向と水平方向の制限)glyph limits vertically and horizontally):
Candera::TextNode2D in SceneComposer の TextNode2D
新しいThe new TextNode2D はツールボックスis パネルにあります。シーンにテキストを追加するには、located in the Toolbox panel. In order to add a text to the scene, drag a TextNode をパネルからfrom the panel to a Scene2D ノードにドラッグします。node.

TextNodeFrom のthe [プロパティ]Properties パネルから、レンダリングに必要なプロパティpanel (of the TextNode, configure the necessary properties for rendering: Text、, Style )を構成します。.

Candera::TextNodeRenderer type of TextNode2D の Candera::TextNode2D TextNodeRendererタイプは、can be changed using the Rendererプロパティを使用して変更できます。 property. Default value in SceneComposer のデフォルト値はis Bitmap です。Bitmap.

Candera::DefaultTextNode2DLayouter は、is attached by checking Enable Text Layoutingをチェックすることでアタッチされます。プロパティ. パネルには、追加のレイアウタAdditional プロパティが表示されます。layouter properties are exposed in the Properties Panel:
複数行Multi line (デフォルトで有効)enabled by default)ワードラップWord wrap (デフォルトでは無効)disabled by default)
-
切り捨てを行うには、For truncation to occur,[テキストEnableレイアウトを有効にするText Layouting]プロパティを有効にする必要があります。property needs to be enabled.

When a TextNode2D が作成されると、is created, a Candera::BitmapBrushColorBlendが自動的にノードに関連付けられ、テキストの色のみを変更するために使用されます。ツールボックス パネルの効果のリストにあるis automatically associated with the node, which is used for changing text color only. Any BitmapBrush 効果は、テキストのレンダリングに使用できます。テキストの視覚的な外観は、選択した効果の種類に応じて影響を受けます。effect present in the list of effects from Toolbox Panel can be used for text rendering. The visual appearance of the text will be affected depending on the type of effect chosen.

TextEngine レンダリングRender インターフェイスInterface
概要:Overview: レンダリングRender インターフェースInterface
テキストをレンダリングするためのメインThe インターフェイスは、メソッドです。main interface to render text is the method
-
Compare this interface also with the functional steps introduced in chapter
このインターフェイスを、Fonts「フォントとスタイル」and Stylesの章で紹介した機能ステップとも比較してください。.
テキストText レンダリングRender コンテキストContext
CanderaA :Candera::TextRendering::TextRenderContext は、テキストis レンダリングのターゲット、つまりテキストのレンダリング先を定義するために必要です。required to define a target for text rendering i.e. where to render the text to.
ビットマップをテキストConfigure レンダリングのターゲットとして構成するBitmap as Target for Text Rendering
A Candera::TextRendering::BitmapTextRenderContext を使用して、テキストをビットマップに描画できます。したがって、まず、描画されるビットマップを次のように定義する必要がありますcan be used to draw text into a bitmap. So first of all the bitmap which shall be drawn needs to be defined with
レンダリングするビットマップを割り当てるthe Candera::TextRendering::BitmapTextRenderContext::SetBitmap()メソッド、method to assign a bitmap to render to,テキストの色を定義するthe Candera::TextRendering::BitmapTextRenderContext::SetPenColor()メソッドmethod to define the text color- the Candera::TextRendering::BitmapTextRenderContext::SetClipRect()
メソッドを使用して、テキストのクリッピング四角形を設定します。method to set a clipping rectangle for the text.
BitmapTextRenderContext bmpRenderContext;
static_cast<void>(bmpRenderContext.SetBitmap(m_bitmap));
bmpRenderContext.SetPenColor(m_color);
レイアウトLayouting オプションOptions
CanderaThe :Candera::TextRendering::LayoutingOptions はレンダリングされたテキストのレイアウトを定義しますdefine the layout of the rendered text with
Canderathe:Candera::TextRendering::LayoutingOptions::SetHorizontalAlignment(SetHorizontalAlignment()およびand Candera::TextRendering::LayoutingOptions::SetVerticalAlignment()メソッドでテキストの配置を指定します。methods to specify the text alignment,複数行レイアウトと単一行レイアウトを切り替えるCanderathe:Candera::TextRendering::LayoutingOptions::SetMultilineTextEnabled()メソッド。method to toggle multi line and single line layout.Canderathe:Candera::TextRendering::LayoutingOptions::SetLineSpacing()メソッドを使用して、複数行のテキストの行間のスペースを変更します。method to modify the space between lines of multi line text.Canderathe:Candera::TextRendering::LayoutingOptions::SetWordWrapEnabled()メソッドを使用して、複数行のテキストの自動ワードラップを有効にします。method to enable automatic word wrap for multi line text.
以下も参照してください。See also:その他のオプションについては、Candera::TextRendering::LayoutingOptionsを参照してください。for further options.
成形オプションShaping Options
CanderaThe :Candera::TextRendering::ShapingOptions は、テキストを論理からディスプレイdefine プレゼンテーションに変換する方法を定義します。コンストラクターのいずれかを使用することをお勧めします。how the text shall be transformed from logical to display presentation. The usage of one of the constructors is recommended:
- Candera::TextRendering::ShapingOptions::ShapingOptions(const StylePtr &style)
- Candera::TextRendering::ShapingOptions::ShapingOptions(const StylePtr &style, const CulturePtr &culture)
テキストText プロパティProperties
CanderaThe :Candera::TextRendering::TextProperties は、レンダリングされるテキスト自体を定義するだけです。simply define the text itself which shall be rendered.
以下も参照してください。See also:コンストラクタthe constructor Candera::TextRendering::TextProperties::TextProperties(const TChar *text, TextLength length)。.
フォントFont メトリックとテキストMetrics サイズand Text Sizes
フォントサイズFont Size
In Canderaでは、フォント サイズthe font size (それぞれのフォントの高さ)respectively をピクセルthe サイズで指定する必要があります。font height) has to be provided in pixel size. Note that in several word processing programs, like Microsoft Wordなどのいくつかのワープロ, プログラムでは、フォントはポイントfonts サイズで定義されていることに注意してください。ピクセルare サイズとポイントdefined サイズの間の変換は、次のように計算されますin point size. The conversion between pixel size and point size is calculated as follows (see FreeType グリフ規則Glyph Conventionsを参照)。):
ピクセル サイズpixel_size =ポイント サイズpoint_size *解像度resolution / 72
たとえば、 Microsoft Windows では、歴史的な理由からe.g. defines for historical reasons a default resolution of 96 PPI (DPI). のデフォルト解像度を定義しています。A font in Microsoft Wordで定義されたポイント サイズwith defined point size 18 のフォントは、has the same height as the font defined in Canderaで定義されたピクセル サイズwith pixel size 24 (24 = 18 * 96/72)のフォントと同じ高さになります。.
フォントFont メトリックMetrics
フォントの場合、フォントFor アセンダー、デバイスa ピクセル単位のディセンダー値、フォント行の高さ、およびフォント文字の最大垂直送り量を記述する静的フォントfont, メトリックが提供されます。static font metrics are provided describing font ascender, descender values in device pixel, the font line height and the maximum vertical advance of a font character: Candera::TextRendering::Font :Font::GetMetrics()
TextRendering::Metrics metrics;
if (!m_font.GetMetrics(metrics)) {
return false;
}
テキスト境界Text Bounds
さらに、指定された文字列のテキスト境界Further, the text bounds (幅、高さなど)width, は、height, etc.) of a given string can be retrieved by calling GetTextRectangle method of Candera::TextRendering::GlyphTextMeasureContextまたは or Candera::TextRendering::CursorTextMeasureContextのCursorTextMeasureContextGetTextRectangleメソッドを呼び出すことによって取得できます。.
Candera::TextRendering::GlyphTextMeasureContext は、すべてのグリフbuilds ビットマップによってカバーされる最小の表面に対応する長方形を構築します。この長方形の位置a rectangle corresponding to the smallest surface covered by all the glyph bitmaps. The position of this rectangle( represented by ((左、上)left, 座標で表される)top) は、テキスト位置からオフセットできます。したがって、テキストをレンダリングするときは、このオフセットの逆数を使用してレイアウトcoordinates) オプションを構築する必要があります。can be offset from the text position. Therefore, when rendering the text, the Layouting Options should be constructed using the inverse of this offset.
Candera::TextRendering::CursorTextMeasureContext は、テキストの処理中に移動するときにカーソルが掃引するサーフェス全体に対応する長方形を作成します。カーソルは、スタイルの高さと同じ長さのセグメントと見なされます。通常、この四角形にはオフセットがなく、カーソルの最終的な前進が含まれます。builds a rectangle corresponding to the whole surface swept by the cursor when moving while processing the text. The cursor is considered to be a segment of length equal to the style height. This rectangle does not usually have an offset and it contains the final advancement of the cursor.
GlyphTextMeasureContext glyphContext;
static_cast<void>(textRenderer.Render(glyphContext, LayoutingOptions(), ShapingOptions(m_style), TextProperties(m_text)));
TextRect textBound = glyphContext.GetTextRectangle();
mTextStartPos.SetX(-textBound.GetPosition().GetX());
mTextStartPos.SetY(-textBound.GetPosition().GetY());
Int16 textWidth = textBound.GetWidth();
Int16 textHeight = textBound.GetHeight();
static_cast<void>(textRenderer.Render(bmpRenderContext, LayoutingOptions(mTextStartPos), ShapingOptions(m_style), TextProperties(m_text)));
レイアウトThe オプションは、テキストのレイアウトを記述します。整形オプションは、テキストの整形方法Layouting Options describe the layout of the text. The Shaping Options define how the text is shaped (合字、テキストの方向など)ligatures, を定義し、スタイルも含みます。text direction, ..) and they also contain the style.
単純なテキストSimple レンダリングText Rendering
シンプルなテキストのレンダリングRendering Simple Text
CanderaThe :Candera::TextRendering::TextRenderer は、テキストをレンダリングするコア関数を提供します。provides the core function to render text.
単純なテキストFor レンダリングの場合、simple text rendering the Candera::TextRendering::TextRenderer::Render()メソッドが呼び出されます。実際のテキスト method is called. Besides the actual text (type TChar*) 型)and とターゲットとしてのthe BitmapTextRenderContext に加えて、レイアウトと整形を指定できます。as target, layouting and shaping can be specified.
static_cast<void>(textRenderer.Render(bmpRenderContext, LayoutingOptions(mTextStartPos), ShapingOptions(m_style), TextProperties(m_text)));
最後に、変更を適用するためにイメージを更新する必要があります。Finally the image has to be updated to apply the changes.
bool success = m_textureImage->Update();
文字とグリフの位置のマッピングCharacter-Glyph Position Mapping
概要Overview
Canderaテキスト エンジンは、文字列の位置をグリフ文字列の位置にマッピングできるインターフェイスを提供します。この機能は、テキストのハイライトなど、文字の位置に応じてさまざまな操作を実行するために、アプリケーションやウィジェットで役立ちます。text engine provides an interface which allows to map positions in character string to positions in glyph string. This feature can be useful for applications and widgets in order to perform various operations depending on the character position like, for instance, highlighting text.
例Example
便宜上、この強調表示機能を使用してFor the convenience, we choose to improve the TextTextureWidget を改善することにしました。with this highlighting feature. The widget will highlight the text by rendering in red all the glyphs corresponding to the characters having the index in the interval ウィジェットは、間隔m_startm_startと and m_endのインデックスを持つ文字に対応するすべてのグリフを赤でレンダリングすることにより、テキストを強調表示します。.
文字位置情報は、The character position information is accessible in the Blit method of the Candera::BitmapTextRenderContextクラスの class. Consequently, this class should be derived and the Blit メソッドでアクセスできます。したがって、このクラスを派生させ、Blitmethod メソッドを次のように上書きする必要があります。overwritten as follows:
class BitmapTextRenderContextSelection : public BitmapTextRenderContext
{
public:
BitmapTextRenderContextSelection(Int selectionStart, Int selectionEnd, Color color) : m_start(selectionStart), m_end(selectionEnd), m_color(color) {}
virtual void Blit(Int16 x, Int16 y, const GlyphBitmap& glyph);
private:
typedef BitmapTextRenderContext Base;
Color ComputeColorForCharPosition(TextPosition position);
Int m_start;
Int m_end;
Color m_color;
};
void BitmapTextRenderContextSelection::Blit(Int16 x, Int16 y, const GlyphBitmap& glyph){
SetPenColor(ComputeColorForCharPosition(glyph.characterPosition));
Base::Blit(x, y, glyph);
}
Color BitmapTextRenderContextSelection::ComputeColorForCharPosition(TextPosition position){
if(position >= m_start && position <= m_end){
return Color(255,0,0);
} else {
return m_color;
}
}
In TextTextureWidget::UpdateTextureImage(), で、use the newly created class instead of の代わりに新しく作成したクラスを使用します。:
BitmapTextRenderContextSelection bmpRenderContext(m_selectionStart, m_selectionEnd, GetTextColorPrv());
双方向テキストの短縮サポートShortening Support For Bidirectional Text
機能の概要Feature Overview
この機能により、指定された表示領域に収まらない場合はいつでも双方向テキストが短縮されます。短縮を行うアルゴリズムは、右から左へのテキストの左から右へのテキストへのさまざまなレベルの埋め込み、およびその逆の埋め込みを処理できます。最後のチャンクのテキストの方向に応じて、短縮文字列は最後のフィッティングThis テキストfeature セグメントの左端または右端に挿入されます。ensures that the bidirectional text shall be shortened whenever it does not fit into its designated display area. The algorithm which does the shortening can deal with different levels of embedding of right-to-left text in left-to-right text and vice versa. Depending on the text direction of the last chunk, the shortening string is inserted after the last fitting text segment, on the left or on the right end.
レンダリングされるシーンのタイプに応じて、次のいずれかを使用して、この機能を利用できます。You can take advantage of this feature by using one of the following, depending on the type of scene being rendered:
| Candera::TextNode2D | - | |
| 3D | - |
Truncation using TextNode2D を使用した切り捨て
この機能は、ノードThis パラメータのfeature [is active only when the node parameter テキストEnable レイアウトを有効にする]Text がLayout有効になっている場合にのみアクティブになります。テキストのサイズがノードの指定された is enabled. The text will be automatically truncated whenever its size no longer fits in the specified Sizeプロパティに収まらなくなると、テキストは自動的に切り捨てられます。 property of the node. TextNode2D は、スペースに合わせてテキストを切り取り、末尾の省略記号を追加するという切り捨て方法をprovides 1only つだけ提供します。one truncation method, by cutting text and adding trailing ellipsis to fit the space.
Truncation using TextTextureWidget を使用した切り捨て
この機能は、ウィジェットThis パラメーターfeature is active only when the widget parameter Truncation method がis set to the Text value. The character(s) used for visual feedback of text shortening is configurable by setting the Truncation textText値に設定されている場合にのみアクティブになります。テキスト短縮の視覚的フィードバックに使用される文字は、 property of the 3D ウィジェットの切り捨てテキストプロパティを設定することで構成できます。widget.
例Examples
以下の画像は、3The つのシナリオを例示しています。image below exemplifies three scenarios :
右から左へのテキストの短縮Shortening of the right-to-left text (アラビア語)Arabic)左から右へのテキストの短縮Shortening of the left-to-right text (ラテン語)Latin)左から右へのテキストに埋め込まれた右から左へのテキストの短縮Shortening of right-to-left text embedded in left-to-right text (左から右および右から左)left-to-right and right-to-left)

フォントヒンティングFont Hinting
概要Overview
フォントFont ヒンティングは、数学的な命令を使用してアウトラインhinting フォントの表示を調整し、ラスタライズされたグリッドに合わせます。これは、フォントをより明確にレンダリングするためにピクセルを補間することによって行われます。画面の解像度が低い場合、明確で読みやすいテキストを生成するには、ヒントが重要です。アンチエイリアシングとis the use of mathematical instructions to adjust the display of an outline font so that it lines up with a rasterized grid. This is done by interpolating the pixels in order to more clearly render the font. At low screen resolutions, hinting is critical for producing clear, legible text. It can be accompanied by antialiasing and (液晶ディスプレイの場合)on サブピクセルliquid レンダリングを併用して、さらに明瞭にすることができます。crystal displays) subpixel rendering for further clarity.
-
ヒンティングはThe hinting applies only toアウトラインoutlineフォントにのみ適用されるため、ビットマップフォントとストロークfontsフォントはこの機能の影響を受けません。so the bitmap fonts and the stroke fonts will not be affected by this feature.
ヒントは通常、書体のデザインHints プロセス中にフォントare エディターで作成され、フォントに埋め込まれます。一般に、グリフにヒントを与えるにはusually 3created つの方法があります。in a font editor during the typeface design process and embedded in the font. In general, there are three possible ways to hint a glyph:
フォントには、ラスタライザーをガイドするためのヒントが含まれており、グリフのどの形状に特別な考慮が必要かを伝えます。ヒンティングTheロジックの一部はフォントにあり、一部はラスタライザーにあります。font contains hints to guide the rasterizer, telling it which shapes of the glyphs need special consideration. The hinting logic is partly in the font and partly in the rasterizer.フォントには、出力デバイスの解像度に応じてアウトラインのポイントを移動する方法に関する正確な指示The font contains exact instructions (バイトコードとも呼ばれる)alsoが含まれており、called bytecode) on how to move the points of its outlines, depending on the resolution of the output device, and which intentionally distort the (アウトライン)outline)形状を意図的に歪ませて、適切にラスタライズされた結果を生成します。ヒントshapeロジックはフォントにあります。理想的には、すべてのラスタライザがこれらの命令を単純に処理して、すべてのプラットフォームで同じ結果を得ることができます。to produce a well-rasterized result. The hinting logic is in the font; ideally, all rasterizers simply process these instructions to get the same result on all platforms.フォントはThe font gets auto-hinted (実行時に)at自動ヒントを取得します。ヒンティングrun-time).ロジックは完全にラスタライザーに含まれています。フォントのヒントは使用または必要ありません。代わりに、ラスタライザーはグリフをスキャンして分析し、それ自体で修正を適用します。The hinting logic is completely in the rasterizer. No hints in the font are used or needed; instead, the rasterizer scans and analyzes the glyphs to apply corrections by itself.
ヒントを有効にするEnabling Hinting
The hinting can be enabled or disabled by the means of the method メソッドCandera:Candera::TextRendering::Font::SetHintingEnabled()を使用して、ヒンティングを有効または無効にすることができます。ヒンティングを無効にすると、以下に示すように、グリフがぼやけて表示される場合があります。テキストは小さなサイズのフォント. When hinting is disabled, the glyphs may appear blurred, as you can see below. The text was rendered with a small size font (9px) でレンダリングされ、ズームインされました。and then zoomed in:

Enabling AutoHint を有効にする
The usage of the automatic hinter of the font driver can be controlled by calling the method Candera::TextRendering::Font::SetAutohintEnabled()メソッドを呼び出すことで、フォント. ドライバーの自動ヒンターの使用を制御できます。自動ヒンターを無効にすると、フォントのネイティブWhen ヒンターが使用されるか、ヒンティングが無効になりますthe automatic hinter is disabled either the native hinter of the font is used either the hinting is disabled (拡大画像)。zoomed in image):

Enabling Force AutoHint を有効にする
特定のフォントIf ドライバーが独自のヒントを提供しない場合、デフォルトで自動ヒントが使用されます。a given font driver doesn't provide its own hinter, the auto-hinter is used by default. If a format-specific hinter is provided, it is still possible to use the auto-hinter by enabling it using the method フォーマット固有のヒントが提供されている場合でも、メソッドCandera:Candera::TextRendering::Font::SetForceAutohintEnabled() を使用して有効にすることで、自動ヒントを使用することができます。.
ヒントモードHinting Mode
ドライバーのオートヒンターは、次のパラメーターThe (ヒンティングdriver アルゴリズム)autohinter のいずれかを指定してcan be configured by calling the Candera::TextRendering::Font::SetHintingMode()メソッドを呼び出すことで構成できます。 method with one of the following parameters(hinting algorithms):
- GlyphHinter::Normal :
標準のグレーレベルnormalレンダリング用に最適化された通常のヒンティングhinting, optimized for standard gray-level rendering

- GlyphHinter::Light :
パフォーマンスを向上させるために、通常のヒンティングよりも少ない修正を適用しますapplies less corrections than normal hinting for better performance

- GlyphHinter::Monochrome :
モノクロのレンダリングに適していますappropriate for monochrome rendering

- GlyphHinter::Lcd :
水平方向にデシメートされたappropriate for horizontally decimated LCDディスプレイに適していますdisplays

- GlyphHinter::VerticalLcd :
垂直方向にデシメートされたappropriate for vertically decimated LCDディスプレイに適していますdisplays

-
All modes except GlyphHinter::Monochrome
を除くすべてのモードは、use 256レベルの不透明度を使用します。levels of opacity.
コード例Code Example
m_font1.SetHintingMode(GlyphHinter::Monochrome);
m_font2.SetHintingMode(GlyphHinter::Light);
グリフGlyph ビットマップ形式Bitmap Format
グリフThe レンダリングoutput プロセスの出力タイプは、メソッドtype of the glyph rendering process can be configured by calling the method Candera::TextRendering::Font::SetRequestedGlyphFormat()を呼び出して、次のレンダリング モードのいずれかをパラメータとして設定できます。with one of the following render modes as parameters:
- GlyphBitmap::Unknown :
形式が指定されていませんformat is unspecified - GlyphBitmap::Monochrome :
1correspondビットのビットマップに対応to 1-bit bitmaps (2twoレベルの不透明度)levels of opacity) - GlyphBitmap::Lcd :
水平方向にデシメートされたformat use with horizontally decimated RGBまたはor BGRサブピクセルsub-pixel LCDディスプレイで使用する形式displays - GlyphBitmap::VerticalLcd :
垂直方向にデシメートされたformat use with vertically decimated LCDディスプレイで使用するフォーマットdisplays - GlyphBitmap::Grayscale :
フォーマットはグレースケールで、1formatピクセルあたりis1grayscale,バイトです。これがデフォルトのレンダリングoneモードですbyte per pixel; this is the default render mode
上記の各レンダリングEach モードは、アウトラインに対して実行される特定の種類のスキャンライン変換に対応しています。of the render modes above correspond to a specific type of scanline conversion performed on the outline.
コード例Code Example
m_font1.SetRequestedGlyphFormat(GlyphBitmap::VerticalLcd);
m_font2.SetRequestedGlyphFormat(GlyphBitmap::Grayscale);
モノクロMonochrome レンダーRender モードMode
モノクロThe レンダリングmonochrome モードでは、2render レベルの不透明度しか使用しないため、アンチエイリアスが削除され、小さなサイズのフォントがより鮮明に表示されますmode removes anti-aliasing because it's using only two levels of opacity and gives clearer appearance for small size fonts (ぼかしなし)。モノクロno レンダリングblurring). モードとグレースケールPlease レンダリングsee モードの比較を以下に示します。below a comparison between monochrome and grayscale render modes:


このレンダリングAn モードを使用するもうanother 1advantage つの利点は、1of ビット形式であるため、グリフのメモリusing フットプリントが小さいことです。this render mode is the smaller memory footprint for glyphs because of 1bit format.