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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
| ' Gambas class file
PRIVATE $hImage AS Image
PUBLIC SUB Form_Open()
ME.Center
txtFontText.Text = Font["17"].ToString() txtText.Text = File.Load("molly-malone.txt")
END
PRIVATE SUB GetText() AS STRING
DIM sText AS STRING
sText = txtText.Text IF NOT btnRichText.Value THEN sText = Replace(Html(sText), "\n", "<br>") RETURN sText
END
PRIVATE SUB RefreshText()
DIM hFont AS Font = Font[txtFontText.Text] DIM sText AS STRING = GetText()
scrText.ResizeContents(scrText.ClientW, hFont.RichTextHeight(sText, scrText.ClientW - 16) + 16) scrText.Refresh
END
PUBLIC SUB scrText_Draw()
DIM sText AS STRING = GetText()
Paint.FillRect(0, 0, Draw.W, Draw.H, Color.TextBackground) TRY Paint.Font = Font[txtFontText.Text] Paint.Translate(-scrText.ScrollX, -scrText.ScrollY) Paint.Background = Color.TextForeground Paint.DrawRichText(sText, 8, 8, scrText.ClientW - 16, scrText.ClientH - 16, Align.TopNormal) 'Debug Paint.ResolutionY;; ":";; Paint.TextSize("toto").Height;; Paint.TextExtents("toto").Height;; "/";; Paint.RichTextSize(sText, scrText.ClientW - 16).Height;; Paint.RichTextExtents(sText, scrText.ClientW - 16).Height
END
PUBLIC SUB btnRichText_Click()
RefreshText
END
PUBLIC SUB txtText_Change()
RefreshText
END
PUBLIC SUB txtFontText_Click()
Dialog.Title = "Select a font" Dialog.Font = Font[txtFontText.Text] IF Dialog.SelectFont() THEN RETURN txtFontText.Text = Dialog.Font.ToString() RefreshText
END
PUBLIC SUB scrText_Arrange()
RefreshText
END
PUBLIC SUB btnOpenText_Click()
Dialog.Title = "Select a text file" IF Dialog.OpenFile() THEN RETURN TRY txtText.Text = File.Load(Dialog.Path)
END
PUBLIC SUB btnPrintText_Click()
IF prtText.Configure() THEN RETURN
ME.Enabled = FALSE INC Application.Busy prtText.Print DEC Application.Busy ME.Enabled = TRUE
END
PUBLIC SUB prtText_Begin()
DIM PRINT_MARGIN AS FLOAT = Paint.Width / prtText.PaperWidth * 10 DIM hExtents AS PaintExtents
Paint.Font = Font[txtFontText.Text] hExtents = Paint.RichTextExtents(GetText(), Paint.Width - PRINT_MARGIN * 2) prtText.Count = Ceil(hExtents.Height / (Paint.Height - PRINT_MARGIN * 2))
END
PUBLIC SUB prtText_Draw()
DIM PRINT_MARGIN AS FLOAT = Paint.Width / prtText.PaperWidth * 10
DEBUG "Printing page";; prtText.Page DEBUG "Paint.FontScale = "; Paint.FontScale DEBUG "Paint.Font.Size = "; Paint.Font.Size DEBUG "Paint.Width = "; Paint.Width DEBUG "Printer.PaperWidth = "; prtText.PaperWidth
Paint.Font = Font[txtFontText.Text] Paint.Rectangle(PRINT_MARGIN / 2, PRINT_MARGIN / 2, Paint.Width - PRINT_MARGIN, Paint.Height - PRINT_MARGIN) Paint.LineWidth = Paint.Width / prtText.PaperWidth * 0.5 Paint.Stroke Paint.Rectangle(PRINT_MARGIN, PRINT_MARGIN, Paint.Width - PRINT_MARGIN * 2, Paint.Height - PRINT_MARGIN * 2) Paint.Clip Paint.DrawRichText(GetText(), PRINT_MARGIN, PRINT_MARGIN - (prtText.Page - 1) * (Paint.Height - PRINT_MARGIN * 2), Paint.Width - PRINT_MARGIN * 2, Paint.Height * prtText.Count, Align.TopNormal) 'Debug Paint.ResolutionY;; ":";; Paint.TextSize("toto").Height;; Paint.TextExtents("toto").Height;; "/";; Paint.RichTextSize(GetText(), Paint.Width - PRINT_MARGIN * 2).Height;; Paint.RichTextExtents(GetText(), Paint.Width - PRINT_MARGIN * 2).Height Paint.ResetClip
END
PUBLIC SUB btnOpenImage_Click()
Dialog.Title = "Select an image file" Dialog.Filter = ["*.png;*.jpg;*.jpeg;*.gif;*.xpm", "Image files"] IF Dialog.OpenFile() THEN RETURN
TRY $hImage = Image.Load(Dialog.Path) scrImage.ResizeContents($hImage.W, $hImage.H) scrImage.Refresh
END
PUBLIC SUB scrImage_Draw()
IF $hImage THEN Draw.Image($hImage, -scrImage.ScrollX, -scrImage.ScrollY)
END
PUBLIC SUB btnPrintImage_Click()
IF prtImage.Configure() THEN RETURN
ME.Enabled = FALSE INC Application.Busy prtImage.Print DEC Application.Busy ME.Enabled = TRUE
END
PUBLIC SUB prtImage_Draw()
DIM PRINT_MARGIN AS FLOAT = Paint.Width / prtText.PaperWidth * 10 DIM hImage AS Image DIM W, H AS FLOAT
IF NOT $hImage THEN RETURN
hImage = $hImage IF hImage.Width > hImage.Height THEN hImage = hImage.Rotate(Pi(0.5))
W = Paint.Width - PRINT_MARGIN * 2 H = W * hImage.Height / hImage.Width Paint.DrawImage(hImage, PRINT_MARGIN, (Paint.Height - H) / 2, W, H)
END
|