| 1 |
Three examples that use libLASi |
| 2 |
=============================== |
| 3 |
|
| 4 |
This directory contains three examples that use libLASi. Below we comment |
| 5 |
on each of these examples, comment on the structure of the resulting |
| 6 |
postscript files, and then give the build instructions for all examples. |
| 7 |
|
| 8 |
MissingGlyphExample |
| 9 |
=================== |
| 10 |
|
| 11 |
The example C++ program, "MissingGlyphExample.cpp" is built into the |
| 12 |
executable, MissingGlyphExample. This example renders the following |
| 13 |
self-explanatory lines of text: |
| 14 |
|
| 15 |
"Display range of glyphs (chosen such that one or more of them normally are missing or", |
| 16 |
"correspond to pure bitmapped fonts) to verify that libLASi does something with low", |
| 17 |
"impact in these cases, i.e., uses the default replacement glyph (normally an empty box)", |
| 18 |
"for all freetype errors generated by missing glyphs or pure bitmap fonts that are", |
| 19 |
"unsuitable for libLASi needs.", |
| 20 |
"", |
| 21 |
"Unicode U+0802 SAMARITAN LETTER GAMAN: ࠂ", |
| 22 |
"Unicode U+08AA ARABIC LETTER REH WITH LOOP: ࢪ", |
| 23 |
"Unicode U+2AF4 TRIPLE VERTICAL BAR BINARY RELATION: ⫴", |
| 24 |
"Unicode U+2AF5 TRIPLE VERTICAL BAR WITH HORIZONTAL STROKE: ⫵", |
| 25 |
"Unicode U+2AF6 TRIPLE COLON OPERATOR: ⫶", |
| 26 |
"Unicode U+2AF7 TRIPLE NESTED LESS-THAN: ⫷", |
| 27 |
"Unicode U+2AF8 TRIPLE NESTED GREATER-THAN: ⫸", |
| 28 |
"Unicode U+1010A AEGEAN NUMBER FOUR: 𐄊", |
| 29 |
"Unicode U+1F70A ALCHEMICAL SYMBOL FOR VINEGAR: 🜊", |
| 30 |
"Unicode U+2648 ARIES (twice): ♈♈", |
| 31 |
"Embedded newlines a\\nb\\nc: a\nb\nc" |
| 32 |
|
| 33 |
Currently, only the last two lines generate empty boxes on my (AWI's) |
| 34 |
Debian Buster platform. |
| 35 |
|
| 36 |
For the line with the two Aries glyphs, pango selects the popular Noto |
| 37 |
Color Emoji glyph to render those glyphs, but that pure bitmap font is |
| 38 |
completely unsuitable for libLASi which only works for outline fonts. |
| 39 |
This example demonstrates that instead of erroring out, libLASi does |
| 40 |
something with low impact for such a pure bitmapped font case and |
| 41 |
replaces each Aries glyph with the default replacement glyph (empty |
| 42 |
box). |
| 43 |
|
| 44 |
For the line with the two embedded line feeds, pango selects an outline |
| 45 |
font that would normally be suitable for use by libLASi. However, |
| 46 |
this non-printing glyph does not exist for that font (which is likely |
| 47 |
to always be the case for all non-printing glyphs for all fonts). |
| 48 |
This example demonstrates that instead of erroring out, libLASi does |
| 49 |
something with low impact for this missing glyph case and replaces |
| 50 |
each requested linefeed glyph with the default replacement glyph |
| 51 |
(empty box). |
| 52 |
|
| 53 |
SimpleLASiExample |
| 54 |
================= |
| 55 |
|
| 56 |
This example C++ program, "SimpleLASiExample.cpp" is built into the |
| 57 |
executable, SimpleLASiExample. This example renders "Hello" in |
| 58 |
Arabic, English, Hebrew, and Hindi. Be sure to obtain the fonts listed |
| 59 |
in the source code, or substitute others present on your machine. See |
| 60 |
http://www.unifont.org/fontguide/ to obtain the Open Source fonts |
| 61 |
specified in the program if you need them. |
| 62 |
|
| 63 |
ComplexTextLayoutExample |
| 64 |
======================== |
| 65 |
|
| 66 |
This example C++ program, "ComplexTextLayoutExample.cpp" is built into |
| 67 |
the executable, ComplexTextLayoutExample. This example demonstrates a |
| 68 |
few additional features of libLASi and also demonstrates the layout of |
| 69 |
complex text layout (CTL) scripts such as Arabic and Indic scripts via |
| 70 |
Pango. This example prints strings in English, Hebrew, Arabic, Thai, |
| 71 |
Japanese, Bengali, and Cyrillic: Be sure to obtain the fonts listed in |
| 72 |
the source code, or substitute others present on your machine. See |
| 73 |
http://www.unifont.org/fontguide/ to obtain the Open Source fonts |
| 74 |
specified in the program if you need them. |
| 75 |
|
| 76 |
Structure of the PostScript Files Resulting from libLASi |
| 77 |
======================================================== |
| 78 |
|
| 79 |
The key thing to notice in these example results is that libLASi |
| 80 |
divides a Postscript document into three parts: a header, a body, and |
| 81 |
a footer. These three parts correspond directly to the document |
| 82 |
structure that you will usually find in a well-structured Postscript |
| 83 |
document. |
| 84 |
|
| 85 |
As shown in the example results, the header can contain Postscript |
| 86 |
convenience procedures that have been defined by the user to ease |
| 87 |
layout. The header will also contain all of the glyph outline |
| 88 |
procedures needed to draw the text of the document. Be sure to examine |
| 89 |
the Postscript output to see what these glyph procedures look like. |
| 90 |
|
| 91 |
The body contains the text that we want to print. Here the "gsave" |
| 92 |
and "grestore" operators are used so that we can change the graphics |
| 93 |
state -- color, rotation, translation, and so on -- and get back to |
| 94 |
the original state after we are done. |
| 95 |
|
| 96 |
Also notice the use of libLASi's setFont(), setFontSize(), and show() |
| 97 |
methods. These methods should remind you of the Postscript "setfont", |
| 98 |
"show" and related commands. But of course here we use libLASi's |
| 99 |
methods so we can manage Unicode text printed using TrueType and |
| 100 |
OpenType fonts. Notice that all of the strings are simply |
| 101 |
null-terminated UTF-8 strings. |
| 102 |
|
| 103 |
Another thing to notice is that we also libLASi's get_dimensions() |
| 104 |
method to help determine the overall bounding box of these examples. |
| 105 |
That method also returns a "lineSpacing". For certain cases we define |
| 106 |
a Postscript "newLine" routine that uses that value to determine the |
| 107 |
spacing between lines. |
| 108 |
|
| 109 |
Finally the footer can contain any additional Postscript Document |
| 110 |
Structuring Conventions, such as the "%%Pages:" directive. |
| 111 |
|
| 112 |
Building the three examples in the core build tree |
| 113 |
================================================== |
| 114 |
|
| 115 |
In the core build tree, the user should configure libLASi with cmake |
| 116 |
and build targets using one of the CMake backends such as the "make" |
| 117 |
command. Building the "all" target builds the library and examples, |
| 118 |
and runs those examples in the examples subdirectory of the build tree |
| 119 |
to generate <example name>.eps EPS (Encapsulated PostScript) files and |
| 120 |
possibly (if inkscape is available to do the conversion) <example |
| 121 |
name>.png PNG files (where <example name> is one of |
| 122 |
MissingGlyphExample, SimpleLASiExample, or ComplexTextLayoutExample). |
| 123 |
The (possible) inkscape conversion from EPS to PNG form is done |
| 124 |
using |
| 125 |
|
| 126 |
inkscape --export-background=\#ffffff --file=<example name>.eps --export-png=<example name>.png |
| 127 |
|
| 128 |
The --export-background option is to impose a white background since |
| 129 |
the EPS result has no background. The result of this conversion is a |
| 130 |
high-quality bitmap representation of the EPS results. Note that |
| 131 |
inkscape is capable of other format transformations as well (e.g., to |
| 132 |
SVG format). |
| 133 |
|
| 134 |
Note such build-time EPS and PNG results are always generated in the |
| 135 |
build tree, and the PNG files examples/<example name>.png *in the |
| 136 |
source tree* are recent (Debian Buster) snapshots of those build-tree |
| 137 |
results which should be a good visual comparison for build-tree EPS |
| 138 |
and PNG results that users obtain on their own platforms by building |
| 139 |
the "all" target. |
| 140 |
|
| 141 |
Building the three examples in the installed examples tree |
| 142 |
========================================================== |
| 143 |
|
| 144 |
In the installed examples tree we use a traditional Makefile + |
| 145 |
pkg-config approach to build and run the examples. The Makefile uses |
| 146 |
"pkg-config" to determine the proper location of headers and libraries |
| 147 |
for libLASi and the libraries that it requires. The pkg-config command |
| 148 |
is available for Linux, Mac OS X, and Windows. If you have problems, |
| 149 |
make sure the environment variable PKG_CONFIG_PATH mentioned in the |
| 150 |
Makefile is modified to include (colon-separated) paths to the |
| 151 |
"freetype2", "pango.pc", and "panggoft2.pc" files. Usually this will |
| 152 |
be in /usr/lib/pkgconfig, /usr/local/lib/pkgconfig, or |
| 153 |
$PREFIX/lib/pkgconfig where $PREFIX is an installation prefix that you |
| 154 |
set up when configuring Pango. |
| 155 |
|
| 156 |
For the installed examples case |
| 157 |
|
| 158 |
make all |
| 159 |
|
| 160 |
should build all the installed examples and run them to produce |
| 161 |
<example name>.eps results, (where <example name> is |
| 162 |
MissingGlyphExample, SimpleLASiExample, or ComplexTextLayoutExample). |
| 163 |
|
| 164 |
The files <example name>.png in the installed example directory are |
| 165 |
automatically installed from the source tree. These PNG files have |
| 166 |
been generated by inkscape from a recent (Debian Buster) snapshot of |
| 167 |
the EPS files <example name>.eps. This PNG form of recent EPS results |
| 168 |
should make a good visual comparison for installed examples EPS |
| 169 |
results that users obtain on their own platform with the above make |
| 170 |
command. |
| 171 |
|
| 172 |
We hope you enjoy using libLASi! |