- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
最佳答案
你的问题让我很好奇,所以尝试了一下,结果如下:
一般绘制彩色字体
显然,FMX 在以后的版本中开箱即用地支持这一点,但在我碰巧拥有的西雅图不支持。我不知道 VCL 在你的版本中是否也支持它,如果不支持,你可以使用 Direct2D 来实现。诀窍是使用 D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT
选项绘制文本。
在 Seattle (10) 中,此常量未定义,并且 - 不幸的是 - 未在默认的 TCanvas 兼容函数中使用。但是您可以自己调用 DrawText
或其他函数之一并指定选项。
大体结构基于this Embarcadero docwiki .其余的是从 TDirect2DCanvas 中看到的,结合 DrawText documentation .
uses Vcl.Direct2D, Winapi.D2D1;
{$R *.dfm}
procedure TForm1.FormPaint(Sender: TObject);
const
str: string = 'xyz👨🏼🎤👩🏾👩🏼👧🏻👦🏿';
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT = 4;
var
c: TDirect2DCanvas;
r: D2D_RECT_F;
begin
c := TDirect2DCanvas.Create(Canvas.Handle, Rect(0, 0, 100, 100));
c.BeginDraw;
try
r.left := 0;
r.top := 0;
r.right := 100;
r.bottom := 50;
// Brush determines the font color.
c.Brush.Color := clBlack;
c.RenderTarget.DrawText(
PWideChar(str), Length(Str), c.Font.Handle, r, c.Brush.Handle,
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
finally
c.EndDraw;
c.Free;
end;
end;
这段代码的工作方式相当丑陋(在定位文本方面),但您也可以查看 TDirect2DCanvas,并复制其中一个文本方法的实现,以创建一个用于输出文本的函数你想要的特定方式。之后,将其应用于您自己的 TGraphicControl 或 TCustomControl 后代以创建支持表情符号的标签应该相当容易。
在 TEdit 中这样做
在 TEdit 中管理它更难,因为绘制文本(和表情符号)是由控件本身处理的。应该可以创建一个 TEdit 后代和/或挂接到它的 WM_PAINT 消息并使用相同的技巧在文本上绘画,但我不确定它的效果如何。
我试了一下,但效果并不理想,尤其是在编辑时。所以我做了这个 TEdit 的后代。聚焦时,它以正常方式绘制文本,彩色表情符号将是黑白的,并分成两个字符(表情符号和颜色组合字符)。当编辑失去焦点时,自定义绘制代码接管,这在这种情况下效果很好。也许您可以尝试对其进行润色以使其在编辑时也能正常工作,但是您必须考虑滚动、定位插入符号和其他内容。对于 TMemo 后代来说,这会更难。我希望您现在对彩色显示感到满意。 :-)
type
TMyEdit = class(Vcl.StdCtrls.TEdit)
protected
procedure PaintWindow(DC: HDC); override;
public
constructor Create(AOwner: TComponent); override;
end;
implementation
uses Vcl.Direct2D, Winapi.D2D1;
{$R *.dfm}
const
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT = 4;
constructor TMyEdit.Create(AOwner: TComponent);
begin
inherited;
DoubleBuffered := True;
end;
procedure TMyEdit.PaintWindow(DC: HDC);
var
c: TDirect2DCanvas;
r: D2D_RECT_F;
begin
// Default drawing when focused. Otherwise do the custom draw.
if Focused then
begin
Inherited;
Exit;
end;
c := TDirect2DCanvas.Create(dc, ClientRect);
c.BeginDraw;
try
r.left := ClientRect.Left;
r.top := ClientRect.Top;
r.right := ClientRect.Right;
r.bottom := ClientRect.Bottom;
// Basic font properties
c.Font.Assign(Font);
// Brush determines the font color.
c.Brush.Color := Font.Color;
c.RenderTarget.DrawText(
PWideChar(Text), Length(Text), c.Font.Handle, r, c.Brush.Handle,
D2D1_DRAW_TEXT_OPTIONS_ENABLE_COLOR_FONT);
finally
c.EndDraw;
c.Free;
end;
end;
关于windows - TEdit 可以显示彩色表情符号吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55447701/
我遇到了 Handlebars 表达式 {{!< default}}我不明白。在问这个问题之前,我曾尝试在谷歌上搜索答案。但是,我找不到任何答案。谁能解释一下这个表达式是什么意思? 最佳答案 在 Ha
经常有朋友问起,如何在im即时通讯中实现发送图片、视频、语音和表情? 为此,小编特意写了一个vue版本的demo,实现了图片视频文件和表情的的发送,参考这个demo源代码,相信你就可以轻松的用un
这里是一个网站 ( https://twitchemotes.com/apidocs ),它展示了一个用于获取 twitch 表情的 API(基本上是描述属于不同用户的一组图像的 json)。 API
使用 Python 3,像下面这样的简单脚本应该按预期运行,但似乎会因 unicode 表情字符串而窒息: import re phrase = "(╯°□°)╯ ︵ ┻━┻" pattern = r
我试图弄清楚表情符号(表情)选择是如何在 Facebook 应用和 Google Hangouts 应用上实现的。我查看了 Android API 示例中的 SoftKeyboard 演示应用程序,但
我正在尝试在 android 通知文本中显示笑脸(或图像范围)。它不起作用。有人知道怎么做吗?谢谢。 代码如下: SpannableStringBuilder builder = new Spanna
我是一名优秀的程序员,十分优秀!