-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprogrammer_guide.txt
More file actions
465 lines (323 loc) · 13.6 KB
/
programmer_guide.txt
File metadata and controls
465 lines (323 loc) · 13.6 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
%% *****************************************************************
%% NOTE: erlPress is very much a work in progress. No doubt the
%% functionality of erlPress_core can be extended in many ways
%% and both code and documentation can be significantly
%% improved.
%%
%% We welcome your involvement. High on our list: support for
%% OpenType and TrueType fonts. And more: We much look forward
%% to creative applications that build on erlPress_core.
%% *****************************************************************
erlPress Programmer’s Guide
erlPress strives to automate print-media editorial/publishng workflow and to deliver the most intuitive possible user interface.
At heart, erlPress involves positioning boxes of various size in two-dimensional space.
Boxes contain other boxes, graphic elements, and text. Much of the code involves translating sets of xy coordinates relative to other xy coordinates. Boxes define the “selected areas” in which output devices “paint” graphic elements and text.
Operationally, “paint” is implemented as sequences of PDF and postscript operators defined in PDF reference manual Version 1.4.
%% *****************************************************************
%% Concepts, technical terms, and jargon
%% *****************************************************************
Concepts, technical terms, and jargon
The history of printing and graphic design stretches back to Johannes Gutenberg’s invention of movable type in 1439 and, no doubt, before.
A rich and descriptive technical vocabulary that facilitates efficient teamwork in the production of printed documents has evolved over over the centuries and is used widely in graphic design studios and print shops today.
For this reason, erlPress employs technical terms and concepts drawn from print/graphic design tradition as well as terms defined in the PDF reference manual.
We've added a few technical/jarony terms of our own.
Here are a few terms that will serve you well as you review and work with erlPress code:
%% *****************************************************************
%% Content
%% *****************************************************************
CONTENT
erlPress composes "content elements" to generate PDF files. Content
includes text, images, and geometric objects. Text may be presented
as "text_blocks", e.g. raw text; "articles"; or "manuscripts."
Content elements have one or more attributes that define the
position, size, and other attributes of the element. These attributes
are represented in erlPress as Erlang maps.
%% *****************************************************************
%% Job
%% *****************************************************************
JOB
This Erlang map defines a "Job":
create(Title, Publisher) ->
#{ title => Title
, publisher => Publisher
, path => "./publishers/" ++ Publisher ++ "/jobs"
, directory => re:replace(Title, " ", "_", [global, {return, list}])
, author => undefined
, subject => undefined
, description => undefined
, keywords => undefined
, start_date => ep_lib:today()
, deadline => undefined
, paper_stock => ?PAPER_STOCK
, page_format => ?PAGE_FORMAT
}.
Note that defaults are provided for several attributes. But the defaults are easily changed.
%% *****************************************************************
%% Metrics
%% *****************************************************************
METRICS
Printers use picas and points as primary units of measure.
1 pica = 1/6 inch
1 point = 12 picas
erlPress uses points for all positioning and size specifications.
erlPress copyfitting routines use 1/1000th of a pica as unit of
measure between glyphs.
To convert a position or size tuple specified in inches, e.g. {X, Y}
or {Width, Height}, to points, execute ...ep_metrics:to_points/2
%% *****************************************************************
%% Paper stock
%% *****************************************************************
PAPER STOCK
Printers feed "paper stock" through their printers to reproduce
printed matter.
To see list of of standard paper sizes used by printers, execute
...ep_paper_stock:standard_sizes/0.
To convert paper stock specified in inches to points, execute
..ep_paper_stock:stock_size_points/1.
To see selected list of paper stock suitable for desktop printers,
execute ..ep_paper_stock:desktop_printer_stock/0.
%% *****************************************************************
%% Boxes
%% *****************************************************************
BOXES
Rectangles or "boxes" are convenient abstractions for placing
content elements on a page.
The PDF reference manual Ver. 1.4 specifies several nested boxes; p. 677:
-- Media box
-- Crop box
-- Bleed box
-- Trim box
-- Art box
Media box is essentially synonomous with dimensions paper stock.
Crop box "defines the region to which the contents of the page are to be
clipped (cropped) when displayed or printed... the crop box will
determine how the page's contents are to be positioned on the output
medium."
Bleed box "defines the region to which the contents of the page should
be clipped when output in a production environment. This may include
some extra 'bleed area' needed to accomodate the physical limitations
of cutting, folding, and trimming equipment."
Trim box "defines the intended dimensions of the finished page after
trimming... The default value is the page's crop box."
Art box "defines the extent of the page's meaningful content... as
intended by the page's creator."
erlPress positions and scales content in "panels." See ../layout/ep_panels.erl.
%% *****************************************************************
%% Imposition
%% *****************************************************************
IMPOSITION
Imposition refers to how the crop box is positioned on the output
medium. If the page is sufficiently smaller than the paper stock
on which it's printed, a bookmark or postcard say, it may be possible
to print two or more pages on the same sheet.
%% *****************************************************************
%% Format
%% *****************************************************************
FORMAT
Format refers to the size and intended functionality of the final
printed piece.
To see list of formats supported by erlPress, execute
rp(ep_format:formats()).
To trim sizes, execute rp(ep_format:format_list()) in the erlPress_core Erlang shell..
%% *****************************************************************
%% Page grid
%% *****************************************************************
PAGE GRID
Graphic designers create "page grids" to organize content on a page.
A page grid is a composition of boxes, each of which represents a block
of text or image.
A well-designed page grid presents a pleasing composition, organized
content, and a controlled "eye-path" guiding the consumer through
the content.
Page grids are represented by a list of "panels" in erlPress. Page grid functions are not yet available in erlPress_core.
%% *****************************************************************
%% Panel
%% *****************************************************************
PANEL
In erlPress, a panel is a box that has width, height, a name and a unique
index number relative to other panels on the page.
This map describes a panel:
create(ID, Position, Size) ->
#{ id => ID
, position => Position
, size => Size
, radius => ?RADIUS
, content_cursor => init_content_cursor(Position)
, border => ?BORDER
, border_style => ?BORDER_STYLE
, border_color => ?BORDER_COLOR
, background_color => ?BACKGROUND_COLOR
, margin => ?MARGIN
, typestyle => ?TYPESTYLE
, indent => ?INDENT
, rot => ?ROT
, jump_prompt => ?JUMP_PROMPT
}.
%% *****************************************************************
%% Type styles
%% *****************************************************************
TYPE STYLES
Type styles are defined in ../typespec. Type styles define type faces,
leading, line justification, and paragrph indentation.
Styles defined to date can be found in:
-- ep_report_sty.erl
-- ep_report_hv_sty.erl
Note that ep_report_sty.erl defines five styles:
- justify_report/1
- ragged_report/1
- preformatted_report/1
- centered_report/1
- ragged_left_report/1
You can use ep_report_sty.erl as a model for defining your own styles.
Functions to access style attributes can be found in ../typespec/ep_typespec.erl
- ep_typespec:get_specs(TypeStyle, Tag)
- ep_typespec:faces(TypeStyle, Tag)
- ep_typespec:fontsize(TypeStyle, Tag)
- ep_typespec:max_linespace(TypeStyle, Tag)
- ep_typespec:leading(TypeStyle, Tag)
- ep_typespec:justify(TypeStyle, Tag)
- ep_typespec:indent(TypeStyle, Tag)
%% *****************************************************************
%% Text
%% *****************************************************************
Refer to examples in ../tests/ep_show_n_tell.erl to see how to display text blocks.
%% **************************************************
%% Text transformations
%% **************************************************
Note the "rot" attribute in the panel map.
This code taken from ../tests/ep_show_n_tell.erl demonstrates how to rotate text:
Text8A = "Th-th-th-that's all folks!",
Font8A = "Helvetica",
TextPosition8A = {450, 550},
FontSize8A = 36,
TextMap8A = ep_text:create(Font8A, TextPosition8A, FontSize8A),
TextMap8B = maps:put(rot, 90, TextMap8A),
ep_text:one_line(PDF, Text8A, Job, TextMap8B),
%% *****************************************************************
%% Content maps
%% *****************************************************************
In addition to text, content elements include images, lines, and geometric shapes.
The module ../tests/ep_show_n_tell.erl demonstrates how to display these elements.
%% *****************************************************************
%% Images
%% *****************************************************************
IMAGE
create(ImageFileName, Position, Size) ->
#{ image_file_name => ImageFileName
, position => Position %% NOTE: bottom left xy of image
, size => Size
}.
%% *****************************************************************
%% Line elements
%% *****************************************************************
LINE
create(From, To) ->
#{ from => From
, to => To
, width => ?DEFAULT_WIDTH
, dash => ?DEFAULT_DASH
, color => ?DEFAULT_COLOR
}.
LINES
create(LineList) ->
#{ lines => LineList
}.
GRID
create(XList, YList) ->
#{ xlist => XList
, ylist => YList
}.
CROPMARK
create(Position) ->
#{position => Position
}.
BEZIER
create(Pt1, Pt2, Pt3, Pt4) ->
#{ from => Pt1
, pt2 => Pt2
, pt3 => Pt3
, to => Pt4
, width => ?DEFAULT_WIDTH
, color => ?DEFAULT_COLOR
}.
%% *****************************************************************
%% Shapes
%% *****************************************************************
CIRCLE
create(Center, Radius) ->
#{ center => Center
, radius => Radius
, border => ?BORDER
, border_style => ?BORDER_STYLE
, border_color => ?BORDER_COLOR
, fill_color => ?FILL_COLOR
}.
DOT
create(Center) ->
#{ center => Center
, radius => ?DEFAULT_RADIUS
, color => black
, border => 1
, border_type => solid
, border_color => black
}.
ELLIPSE
create(Center, Axes) ->
#{ center => Center
, axes => Axes
, border => ?DEFAULT_BORDER
, border_style => ?DEFAULT_BORDER_STYLE
, border_color => ?DEFAULT_BORDER_COLOR
, fill_color => ?DEFAULT_FILL_COLOR
}.
POLYGON
create(Vertices) ->
#{ vertices => Vertices
, outline => ?OUTLINE_WIDTH
, dash => ?DASH
, outline_color => ?OUTLINE_COLOR
, fill_color => ?FILL_COLOR
}.
RECTANGLE
create(Position, Size) ->
#{ position => Position
, size => Size
, outline => ?BORDER
, outline_style => ?BORDER_STYLE
, outline_color => ?BORDER_COLOR
, fill_color => ?FILL_COLOR
}.
ROUNDED RECTANGLE
create(Position, Size, Radius) ->
#{ position => Position
, size => Size
, radius => Radius
, border => ?BORDER
, border_style => ?BORDER_STYLE
, border_color => ?BORDER_COLOR
, background_color => ?BACKGROUND_COLOR
}.
%% **************************************************
%% Page layout
%% **************************************************
Future work.
%% **************************************************
%% Articles and Beads
%% **************************************************
Future work.
%% *****************************************************************
%% Road Map/Wish List
%% *****************************************************************
Road Map/Wish List
- Extended Markdown text input
- Page layout tools
- Articles and Beads
- Initial caps
- Footnotes
- Guru challenge: Wouldn't it be neat to wrap text in a circle or
ellipse with even margin all the way around
— Support for Open Type and True Type fonts
— GUI - Fontmap editor
— GUI - Text editor
— Document design/layout editor
— One-input multiple-output functionality; e.g. true output device independence, both digital and print