如何在画布上,在定义的Rect内部绘制, MULTILINE 文本,其中一些单词为粗体/彩色?在firemonkey上......
这与How to draw text with different font formatting to a canvas in delphi at once?的问题不同,因为我想在firemonkey上绘制多行文字!打破以适合Rect内部的文本。类似于canvas.FillText,但有一种方法可以用粗体/彩色设置一些单词
答案 0 :(得分:1)
所以我最终编写了自己的功能打破文本。这个函数太大了,无法在这里发布,但你可以看到它https://svn.code.sf.net/p/alcinoe/code/单位alFmxCommon
function ALDrawMultiLineText(const aText: String; // support only theses EXACT html tag :
// <b>...</b>
// <i>...</i>
// <font color="#xxxxxx">...</font>
// <span id="xxx">...</span>
// other < > must be encoded with < and >
var aRect: TRectF; // in => the constraint boundaries in real pixel. out => the calculated rect that contain the html in real pixel
var aTextBreaked: boolean; // true is the text was "breaked" in several lines
var aAscent: single; // out => the Ascent of the last element (in real pixel)
var aDescent: Single; // out => the Descent of the last element (in real pixel)
var aFirstPos: TpointF; // out => the point of the start of the text
var aLastPos: TpointF; // out => the point of the end of the text
var aElements: TalTextElements; // out => the list of rect describing all span elements
var aEllipsisRect: TRectF; // out => the rect of the Ellipsis (if present)
const aOptions: TALDrawMultiLineTextOptions): {$IFDEF _USE_TEXTURE}TTexture{$ELSE}Tbitmap{$ENDIF};
在几行中打破文本并为此文本添加格式并为所有平台添加格式
绝对不是一件容易的事。