WPCubed Product Support

Draw text as contour / draw text as outline

wpsupport

From the quoted PS code I cannot see why it is not rendered. Maybe the "S" is missing at the end.

You can use this utility function which requires a reference canvas:

procedure TextOutOutline( ReferenceCanvas, Canvas : TCanvas; X,Y : Integer; const Text : String );
var dc : HDC;
    l, q : Integer;
    points: array of TPoint;
    types: array of Byte;
begin
       ReferenceCanvas.Font.Assign(Canvas.Font);
       dc := ReferenceCanvas.Handle;

       BeginPath(dc);
       ReferenceCanvas.TextOut(0,0,Text);
       EndPath(dc);

       SetLength(points, 1);
       SetLength(types, 1);
       l := GetPath(dc, @points[0], @types[0], 0);
       SetLength(points, l);
       SetLength(types, l);
       GetPath(dc, @points[0], @types[0], l);

       for q := 0 to l-1 do
       begin
         inc(points[q].X, x);
         inc(points[q].Y, Y);
       end;

       q := 1;
       while (q < l) and (types[q] <> 6) and (q < 5) do inc(q);
       if q<l then
       PolyDraw(Canvas.Handle, points[q], types[q], l-q);
end;

It is used like this:

WPPDFPrinter1.Canvas.Brush.Color := clRed;
WPPDFPrinter1.Canvas.Pen.Color := clYellow;
WPPDFPrinter1.Canvas.Font.Size := 100;
BeginPath(WPPDFPrinter1.Canvas.Handle);
TextOutOutline(Canvas, WPPDFPrinter1.Canvas,  10, 10, 'Outline');
EndPath(WPPDFPrinter1.Canvas.Handle);
StrokeAndFillPath(WPPDFPrinter1.Canvas.Handle); 

TextOutOutline Create the path data using a canvas which is not visible and then renders it to the wPDF Canvas.

The code also skips the first part of the path data because it is usually only the bounding box of the output.

#2 ♥ 0
2.5k Views 2 users read 2 min

Hello,

when text is printed as contour with the activated modes wpTextAsGlyphs, wpRenderTextInPathAsGlyph and this code:

    OldBkMode := SetBkMode(Canvas.Handle, TRANSPARENT);
    BeginPath(Canvas.Handle);
    Canvas.TextOut(X, Y, Text);
    EndPath(Canvas.Handle);
    StrokeAndFillPath(Canvas.Handle);
    SetBkMode(Canvas.Handle, OldBkMode);

the glyphs are in the pdf source (Q 1 g 1 0 0 RG 20 w 1 J 1 j [] 0 d 1 0 0 1 0 0 cm q 0.064 0 0 0.064 192 -192 cm 1 0 0 rg 43 449 m 43 522 54 583 76 633 c 92 669 114 702 142 731 c 171 760 202 781 235 796 c 280 814 331 824 390 824 c ...) but nothing is shown in Acrobat.

Is it possible to draw the contour of the characters?

Regards,

Thomas

#1 ♥ 0