summaryrefslogtreecommitdiff
path: root/docview/components/richtext/RichTextPrintUnit.pas
blob: 01746c6861b1f0d5ff0bd7a6aa8738674d395c04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
Unit RichTextPrintUnit;

Interface

uses
  Graphics,
  RichTextStyleUnit;

// Prints the specified rich text, starting at page position PageY.
// Starts new pages as needed; when done, PageY is the final position used
// on the final page.
Procedure PrintRichText( Text: PChar;
                         Images: TImageList;
                         Settings: TRichTextSettings;
                         var PageY: longint );

Implementation

uses
  Classes,
  Printers,
  CanvasFontManager,
  RichTextLayoutUnit, RichTextDisplayUnit, Forms
  ;

Procedure PrintRichText( Text: PChar;
                         Images: TImageList;
                         Settings: TRichTextSettings;
                         var PageY: longint );
var
  Layout: TRichTextLayout;
  FontManager: TCanvasFontManager;
  LineIndex: longint;
  Y: longint;
  FinishLine: longint;
  FinishY: longint;
Begin
  FontManager := TCanvasFontManager.Create( Printer.Canvas,
                                            false // don't allow bitmap fonts
                                          );

  Layout := TRichTextLayout.Create( Text,
                                    Images,
                                    Settings,
                                    FontManager,
                                    Printer.PageWidth );

  LineIndex := 0;
  Y := PageY;
  repeat
    PrintRichTextLayout( FontManager,
                         Layout,
                         LineIndex,
                         FinishLine,
                         Y,
                         FinishY );
    LineIndex := FinishLine;
    Y := FinishY;

    if LineIndex < Layout.FNumLines then
    begin
      // didn't all fit on page, so new page
      Printer.NewPage;
      Y := Printer.PageHeight - 1;
    end;

  until LineIndex >= Layout.FNumLines;

  Layout.Destroy;
  FontManager.Destroy;
  PageY := Y;
end;

Initialization
End.