delphi - TDirect2DCanvas 中的字体方向不起作用?

标签 delphi orientation direct2d

我需要在 TDirect2DCanvas 上绘制有角度的文本,但没有成功。

procedure TForm1.FormPaint(Sender: TObject);
var
  LCanvas: TDirect2DCanvas;
const
  myText = 'Kikimor';
begin
   LCanvas := TDirect2DCanvas.Create(Canvas, ClientRect);
   LCanvas.BeginDraw;
   try
     LCanvas.Font.Orientation := 90;
     LCanvas.TextOut(100,100,myText);
   finally
     LCanvas.EndDraw;
     LCanvas.Free;
   end;
end;

无论我给出什么方向的角度,它总是绘制直的文本。 定向不起作用还是我需要做其他事情?

最佳答案

设置 TDirect2DCanvas.Font.Orientation 没有任何效果(很可能没有实现,抱歉,没有时间调试)。 Delphi 中提供的 Direct2D 包装器非常基础。

为了实现您的目标,请手动应用转换:

procedure TForm1.FormPaint(Sender: TObject);
var
  LCanvas: TDirect2DCanvas;
  currentTransform: TD2D1Matrix3x2F;
  ptf: TD2DPoint2f;
const
  myText = 'Kikimor';
begin
  LCanvas := TDirect2DCanvas.Create(self.Canvas, ClientRect);
  LCanvas.BeginDraw;
  try
//    backup the current transformation
    LCanvas.RenderTarget.GetTransform(currentTransform);
    ptf.x:= 100.0; ptf.y:= 100.0;  //rotation center point
// apply transformation to rotate text at 90 degrees:
    LCanvas.RenderTarget.SetTransform(TD2D1Matrix3x2F.Rotation(90, ptf));
// draw the text (rotated)
    LCanvas.TextOut(100, 100, myText);
// restore the original transform
    LCanvas.RenderTarget.SetTransform(currentTransform);
  finally
    LCanvas.EndDraw;
    LCanvas.Free;
  end;
end;

有关更广泛的信息/效果,您可以查看: Drawing text using the IDWriteTextLayout.Draw() 整体Direct2D同一网站上的类别也很有趣(使用谷歌翻译)。

关于delphi - TDirect2DCanvas 中的字体方向不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56478296/

相关文章:

delphi - 如何解决打开项目时 Delphi XE 中的 bpl 加载问题?

android - 如何使android TextureView以正确的方向显示视频

javascript - 绕 z 轴旋转时 iOS 陀螺仪错误

delphi - 为什么 TList.Remove() 会产生 EAccessViolation 错误?

Delphi 类变量在调用类析构函数之前超出范围

delphi - Delphi 2010 Enterprise 版本的哪些功能对您有值(value),为什么?

c++ - Direct2D 拒绝在窗口上绘制位图,静默失败

php - 在 PHP 中检索图像方向

directx - 检索用于创建 ID2D1RenderTarget 的 IDXGISurface

visual-c++ - 使用 Direct2D 绘制圆形进度条