File: MissingGlyphExample.cpp

package info (click to toggle)
lasi 1.1.3-2.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,756 kB
  • sloc: cpp: 1,360; javascript: 139; sh: 20; makefile: 13
file content (94 lines) | stat: -rw-r--r-- 2,808 bytes parent folder | download | duplicates (2)
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
// MissingGlyphExample.cpp

#include <iostream>
#include <fstream>
#include <stdexcept>
#include <LASi.h>

#ifndef MAX
#define MAX( a, b )                      ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
#ifndef MIN
#define MIN( a, b )                      ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif

using namespace LASi;
using namespace std;

int main(const int argc, char* const argv[]) 
{
  ofstream strm;

  try {
    PostscriptDocument doc;
    int i, x=10, y=800, fixed_lineSpacing=25;
    double xAdvance,yMinimum,yMaximum,lineSpacing;
    double llx=x,urx=x,lly=y,ury=y;
    int nstrings = 17;
    const char * strings[17] = {
      "Display range of glyphs (chosen such that one or more of them normally are missing or",
      "correspond to pure bitmapped fonts) to verify that libLASi does something with low",
      "impact in these cases, i.e., uses the default replacement glyph (normally an empty box)",
      "for all freetype errors generated by missing glyphs or pure bitmap fonts that are",
      "unsuitable for libLASi needs.",
      "",
      "Unicode U+0802 SAMARITAN LETTER GAMAN: ࠂ",
      "Unicode U+08AA ARABIC LETTER REH WITH LOOP: ࢪ",
      "Unicode U+2AF4 TRIPLE VERTICAL BAR BINARY RELATION: ⫴", 
      "Unicode U+2AF5 TRIPLE VERTICAL BAR WITH HORIZONTAL STROKE: ⫵", 
      "Unicode U+2AF6 TRIPLE COLON OPERATOR: ⫶", 
      "Unicode U+2AF7 TRIPLE NESTED LESS-THAN: ⫷", 
      "Unicode U+2AF8 TRIPLE NESTED GREATER-THAN: ⫸", 
      "Unicode U+1010A AEGEAN NUMBER FOUR: 𐄊",
      "Unicode U+1F70A ALCHEMICAL SYMBOL FOR VINEGAR: 🜊",
      "Unicode U+2648 ARIES (twice): ♈♈",
      "Embedded newlines a\\nb\\nc: a\nb\nc",
    };

    //
    // Set font to generic "serif":
    //
    doc.osBody() << setFont("serif") << setFontSize(18) << endl;
    doc.osBody() << x << " " << y << " moveto" << endl;
    for(i=0;i<nstrings; i++)
    {
      doc.osBody() << show(strings[i]);
      doc.get_dimensions(strings[i],&lineSpacing,&xAdvance,&yMinimum,&yMaximum);
      // Calculate total bounding box
      llx = x-1;
      urx = MAX(urx, x+xAdvance+1);
      lly = MIN(lly, y+yMinimum-1);
      ury = MAX(ury, y+yMaximum+1);
      y -= fixed_lineSpacing;
      doc.osBody() << x << " " << y << " moveto" << endl;
    }

    //
    // Postscript showpage:
    //
    doc.osBody() << "showpage" << endl;
    
    // Write out postscript document, including bounding box. 
    // If the bounding box arguments are omitted then no
    // bounding box is included in the file.
    //
    if (argc == 1) {
      doc.write(cout,llx,lly,urx,ury);
    }
    else {
      strm.open(argv[1]);
      doc.write(strm,llx,lly,urx,ury);
      strm.close();
    }
    
  } catch (runtime_error& e) {
  
    cerr << e.what() << endl;
    return 1;
    
  }

  return 0;
  
}