Webinar demo creates a PDF from a bitmap of the control, as a result PDF does not scale well.
With a fix in Skia I do create scalable PDFs on Windows (where Printer canvas is available),
but this solution is not portable, at least for Android.
Not a specific control, just a [derived] control containing rectangles and text.
The closest I came across is for VCL, it creates a canvas to render to:
litePDF example
Thanks for a quick reply!
The problem of rendering to a different canvas (rather than default) is an FMX problem, not Skia problem.
The TTextLayout derivative is bound to the default canvas when created and knows nothing about some other canvas type.
I created a workaround which works on Windows, other platforms are untested:
type
TTextLayoutX = class(TTextLayout);
procedure TSkTextLayout.DoDrawLayout(const ACanvas: TCanvas);
var
layoutClass: TTextLayoutClass;
layout: TTextlayout;
begin
if (ACanvas is TSkCanvasCustom) and Assigned(TSkCanvasCustom(ACanvas).Surface) then
DoDrawLayout(TSkCanvasCustom(ACanvas).Surface.Canvas)
else begin //
{$REGION 'A-Dato workaround for printing (on GDI+)'}
layoutClass := TTextLayoutManager.TextLayoutByCanvas(ACanvas.ClassType);
if (layoutClass <> nil) then begin
layout := layoutClass.Create;
layout.TopLeft := TopLeft;
layout.MaxSize := MaxSize;
layout.Text := Text;
layout.Padding := Padding;
layout.WordWrap := WordWrap;
layout.HorizontalAlign := HorizontalAlign;
layout.VerticalAlign := VerticalAlign;
//layout.VerticalAlign := TTextAlign.Trailing; //too low
layout.Color := Color;
layout.Font := Font;
layout.Opacity := Opacity;
layout.RightToLeft := RightToLeft;
TTextLayoutX(layout).DoDrawLayout(ACanvas);
end;
{$ENDREGION}
end;
end;
A second question about printing:
Skia has an example of rendering to a PDF canvas, but this canvas is of a TskCanvas class
and thus not compatible with FMX adapter class TSkCanvasCustom (which uses TskCanvas internally).
Is there an easy way to create TSkCanvasCustom from a given TskCanvas instance?
Has anybody tried to do printing of an control ?
The TextLayout is bound to TSkCanvasCustom for display but the printing goes to GDI+ canvas,
which custom TextLayout knows nothing about. As a result all text is missing in the printout.