1

我在 Delphi 7 中有以下代码沿 DVD 的弯曲边缘绘制版权文本。我们使用的是旧版本的 Graphics32。

我们正在使用 Graphics32 的最新代码切换到 Delphi XE5,并且该代码不再编译;特别是 LoadArcCurve 和 drawingBuffer.RenderFittedText 不再作为方法存在。

procedure TCDLabel.DrawCopyrightText(const drawingBuffer: TBitmap32Ex);
var
  FixedPointArray : TArrayOfFixedPoint;
  Center : TFixedPoint;
  vAngle1 : double;
  vAngle2 : double;
  radius : integer;
  CopyrightText : string;
  textColor : TColor32;
begin
  radius := (fImageSize div 2) - 30;
  UpdateTextTransform(8{2.3}, drawingBuffer);
  Center.x := GR32.Fixed(fImageSize div 2);
  Center.y := GR32.Fixed(fImageSize div 2);
  vAngle1 := DegToRad(-130);
  textColor := clWhite32;
  vAngle2 := DegToRad(0);
  LoadArcCurve(Center, GR32.Fixed(radius), GR32.Fixed(radius), vAngle1, vAngle2, FixedPointArray);
  CopyrightText := Format('%s %s Dystopia Unlimited. All rights reserved.', [GetCopyrightSymbol, fCopyrightYears]);
  drawingBuffer.RenderFittedText(CopyrightText, textColor, pdoAntialising or pdoFilling, FixedPointArray);
  FixedPointArray := NIL;
end; {DrawCopyrightText}

我使用最新的 Graphic32 代码在 Delphi XE5 中有以下代码片段,并尝试了各种其他类似的方法,但均未成功。

canvas := TCanvas32.Create(drawingBuffer); // drawingBuffer is a TBitmap32
try
  canvas.Brushes.Add(TStrokeBrush);
  canvas.Brushes[0].Visible := TRUE;
  (canvas.Brushes[0] as TStrokeBrush).StrokeWidth := 2;
  (canvas.Brushes[0] as TStrokeBrush).FillColor := clWhite32;

  canvas.Path.BeginPath;
  canvas.Path.Arc(Center, -130, 0, radius);
  canvas.Path.EndPath;
  TextToPath(drawingBuffer.Font.Handle, canvas.Path, FloatRect(0, 0, fImageSize, fImageSize), CopyrightText);

我可以找到的新 Graphics32 中的所有示例似乎都直接绘制到 Delphi 控件画布上,而我需要绘制到 TBitmap32 上。

如何使用 Delphi XE5 和最新版本的 Graphics32 在图像/位图中沿弧线渲染文本?

4

2 回答 2

2

我认为实现您所描述的最佳方法是使用 Angus Johnson 对 graphics32 的出色扩展GR32_Text

于 2014-09-22T14:44:09.347 回答
1

使用 David Heffernan 提供的指向 Angus Johnson 的工作的指针,以下代码是我的问题的解决方案。

此代码使用单位:GR32_Lines、GR32_Text、GR32_Misc 以及其他。它也不保护内存或执行可发布代码所需的任何其他保护过程。

procedure DrawCopyrightText(const drawingBuffer: TBitmap32);
var
  fixedPointArray : TArrayOfFixedPoint;
  CopyrightText : string;
  ttFont : TTrueTypeFont;
  text32 : TText32;
  i: integer;
  polyPolyPts: TArrayOfArrayOfArrayOfFixedPoint;
begin
  CopyrightText := Format('%s %s Dystopia Unlimited. All rights reserved.', [GetCopyrightSymbol, fCopyrightYears]);

  text32 := TText32.Create;
  ttFont := TTrueTypeFont.Create(COPYRIGHT_FONT_NAME, COPYRIGHT_FONT_SIZE);
  fixedPointArray := GetArcPoints(FloatRect(30, 30, 2370, 2370), -140, 0);
  polyPolyPts := text32.GetEx(fixedPointArray, CopyrightText, ttFont, aLeft, aMiddle, true, 2);
  for i := 0 to high(polyPolyPts) do
    if length(polyPolyPts[i]) > 0 then
      SimpleFill(drawingBuffer, polyPolyPts[i], clWhite32, clWhite32);
end;
于 2014-09-22T14:50:21.333 回答