Debian Codegraph @

podofo/staging/ExtractFontInfos.cpp

raw
1 #include <iostream>
2 #include <cassert>
3 #include <filesystem>
4
5 #include <podofo/podofo.h>
6 #include <podofo/private/PdfDeclarationsPrivate.h>
7 #include <podofo/private/FreetypePrivate.h>
8
9 #include <freetype/t1tables.h>
10
11 using namespace std;
12 using namespace PoDoFo;
13 namespace fs = std::filesystem;
14
15 int main(int argc, char* argv[])
16 {
17 (void)argc;
18 (void)argv;
19
20 auto teXGyreFontsPath = fs::u8path(utls::GetEnvironmentVariable("LIBERATION_SLIM_FONTS_PATH"));
21 if (teXGyreFontsPath.empty())
22 throw runtime_error("LIBERATION_SLIM_FONTS_PATH environment variable is missing");
23
24 vector<string> fonts = {
25 "LiberaLeanSerif-Regular.otf",
26 "LiberaLeanSerif-Italic.otf",
27 "LiberaLeanSerif-Bold.otf",
28 "LiberaLeanSerif-BoldItalic.otf",
29 "LiberaLeanSans-Regular.otf",
30 "LiberaLeanSans-Italic.otf",
31 "LiberaLeanSans-Bold.otf",
32 "LiberaLeanSans-BoldItalic.otf",
33 "LiberaLeanMono-Regular.otf",
34 "LiberaLeanMono-Italic.otf",
35 "LiberaLeanMono-Bold.otf",
36 "LiberaLeanMono-BoldItalic.otf",
37 };
38
39 charbuff buffer;
40 //for (auto& filepath : fonts)
41 auto fontName = fonts[0];
42 {
43 auto metrics = PdfFontMetrics::Create((teXGyreFontsPath / fontName).u8string());
44 auto matrix = metrics->GetMatrix();
45
46 unsigned count = metrics->GetGlyphCount();
47 for (unsigned i = 0; i < count; i++)
48 {
49 cout << " " << (int16_t)(std::round(metrics->GetGlyphWidth(i) * 1000)) << "," << endl;
50 }
51
52 auto face = const_cast<PdfFontMetricsFreetype&>(static_cast<const PdfFontMetricsFreetype&>(*metrics)).GetFaceHandle();
53
54 FT_Error rc = FT_Select_Charmap(face, FT_ENCODING_UNICODE);
55 assert(rc == 0);
56
57 PS_PrivateRec rec;
58 rc = FT_Get_PS_Font_Private(face, &rec);
59
60 FT_ULong charcode;
61 FT_UInt gindex;
62
63 charcode = FT_Get_First_Char(face, &gindex);
64 std::map<unsigned short, unsigned short> map;
65 while (gindex != 0)
66 {
67 assert(charcode < 65536);
68 map.insert({ (unsigned short)charcode, (unsigned short)gindex });
69 charcode = FT_Get_Next_Char(face, charcode, &gindex);
70 }
71
72 char buff[2];
73 unsigned char ch;
74 for (auto& pair : map)
75 {
76 cout << " { 0x";
77 ch = (unsigned char)(pair.first >> 8 & 0xFFu);
78 utls::WriteCharHexTo(buff, ch);
79 cout << string(buff, 2);
80 ch = (unsigned char)(pair.first & 0xFFu);
81 utls::WriteCharHexTo(buff, ch);
82 cout << string(buff, 2) <<", " << pair.second << " }," << endl;
83 }
84
85 cout << " " << (int16_t)(std::round(metrics->GetDefaultWidth() * 1000)) << "," << endl;
86 cout << " " << "PdfFontStretch::Normal," << endl;
87 cout << " " << (int16_t)(std::round(metrics->GetAscent() * 1000)) << "," << endl;
88 cout << " " << (int16_t)(std::round(metrics->GetDescent() * 1000)) << "," << endl;
89 cout << " " << (int16_t)(std::round(metrics->GetXHeight() * 1000)) << "," << endl;
90 cout << " " << (int16_t)(std::round(metrics->GetCapHeight() * 1000)) << "," << endl;
91 cout << " " << (int16_t)(std::round(metrics->GetItalicAngle() * 1000)) << "," << endl;
92 cout << " " << metrics->GetWeight() << "," << endl;
93 cout << " " << (int16_t)(std::round(metrics->GetStemV() * 1000)) << "," << endl;
94 cout << " " << (int16_t)(std::round(metrics->GetStemH() * 1000)) << "," << endl;
95 cout << " " << (int16_t)(std::round(metrics->GetStrikeThroughPosition() * 1000)) << "," << endl;
96 cout << " " << (int16_t)(std::round(metrics->GetUnderlinePosition() * 1000)) << "," << endl;
97 auto box = metrics->GetBoundingBox();
98 cout << " " << "Corners("
99 << (int16_t)(std::round(box.GetCorner1().X * 1000)) << ", "
100 << (int16_t)(std::round(box.GetCorner1().Y * 1000)) << ", "
101 << (int16_t)(std::round(box.GetCorner2().X * 1000)) << ", "
102 << (int16_t)(std::round(box.GetCorner2().Y * 1000))
103 << ")" << endl;
104 }
105
106 return 0;
107 }