diff options
author | Werner Lemberg <wl@gnu.org> | 2018-07-23 19:42:28 +0200 |
---|---|---|
committer | Werner Lemberg <wl@gnu.org> | 2018-07-23 19:48:50 +0200 |
commit | ae4b51e97b8785e938b4053dd38b3a43a1bde885 (patch) | |
tree | 873b151774ac40c04504e3100ff2143a25d02760 | |
parent | 2364da8e3aff1b2b4eda36d63ba775443db67c1f (diff) |
example5.cpp: Make it `more C++'.
Contributed by Static Jobs LLC.
The SVG file was regenerated using version 2.00.1 of
`LiberationSerif-Bold.ttf'.
-rw-r--r-- | freetype2/docs/tutorial/example5.cpp | 66 | ||||
-rw-r--r-- | freetype2/docs/tutorial/example5.svg | 128 | ||||
-rw-r--r-- | freetype2/docs/tutorial/step3.html | 2 |
3 files changed, 97 insertions, 99 deletions
diff --git a/freetype2/docs/tutorial/example5.cpp b/freetype2/docs/tutorial/example5.cpp index ea976f3..3251ba7 100644 --- a/freetype2/docs/tutorial/example5.cpp +++ b/freetype2/docs/tutorial/example5.cpp @@ -5,7 +5,7 @@ // // Developed by Static Jobs LLC and contributed to the FreeType project. // -// Copyright (c) 2016 Static Jobs LLC +// Copyright (c) 2016-2018 Static Jobs LLC // IT and software engineering jobs in the US, Canada and the UK // https://www.staticjobs.com // @@ -16,11 +16,11 @@ // // On a Unix box like GNU/Linux or OS X, compile with // -// g++ -o example5 example5.cpp `freetype-config --cflags --libs` +// g++ -o example5 example5.cpp `pkg-config freetype2 --cflags --libs` // // or // -// g++ -o example5 example5.cpp `pkg-config freetype2 --cflags --libs` +// g++ -o example5 example5.cpp `freetype-config --cflags --libs` // // on the command line. // @@ -64,11 +64,20 @@ using namespace std; -struct FreeTypeLibrary +// A minimal wrapper for RAII (`resource acquisition is initialization'). +class FreeTypeLibrary { +public: FreeTypeLibrary(); ~FreeTypeLibrary(); + operator FT_Library() const; + +private: + FreeTypeLibrary(const FreeTypeLibrary &); + FreeTypeLibrary &operator =(const FreeTypeLibrary &); + +private: FT_Library m_ftLibrary; }; @@ -91,12 +100,28 @@ FreeTypeLibrary::~FreeTypeLibrary() } -struct FreeTypeFace +inline +FreeTypeLibrary::operator FT_Library() const +{ + return m_ftLibrary; +} + + +// Another minimal wrapper for RAII. +class FreeTypeFace { +public: FreeTypeFace(const FreeTypeLibrary &library, const char *filename); ~FreeTypeFace(); + operator FT_Face() const; + +private: + FreeTypeFace(const FreeTypeFace &); + FreeTypeFace &operator =(const FreeTypeFace &); + +private: FT_Face m_ftFace; }; @@ -106,7 +131,7 @@ FreeTypeFace::FreeTypeFace(const FreeTypeLibrary &library, const char *filename) { // For simplicity, always use the first face index. - FT_Error error = FT_New_Face(library.m_ftLibrary, filename, 0, &m_ftFace); + FT_Error error = FT_New_Face(library, filename, 0, &m_ftFace); if (error) throw runtime_error("Couldn't load the font file:" @@ -114,12 +139,20 @@ FreeTypeFace::FreeTypeFace(const FreeTypeLibrary &library, } -inline FreeTypeFace::~FreeTypeFace() +inline +FreeTypeFace::~FreeTypeFace() { FT_Done_Face(m_ftFace); } +inline +FreeTypeFace::operator FT_Face() const +{ + return m_ftFace; +} + + class OutlinePrinter { public: @@ -127,6 +160,10 @@ public: int Run(const char *symbol); private: + OutlinePrinter(const OutlinePrinter &); + OutlinePrinter &operator =(const OutlinePrinter &); + +private: void LoadGlyph(const char *symbol) const; bool OutlineExists() const; void FlipOutline() const; @@ -206,9 +243,9 @@ OutlinePrinter::LoadGlyph(const char *symbol) const // For simplicity, use the charmap FreeType provides by default; // in most cases this means Unicode. - FT_UInt index = FT_Get_Char_Index(m_face.m_ftFace, code); + FT_UInt index = FT_Get_Char_Index(m_face, code); - FT_Error error = FT_Load_Glyph(m_face.m_ftFace, + FT_Error error = FT_Load_Glyph(m_face, index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); @@ -220,14 +257,14 @@ OutlinePrinter::LoadGlyph(const char *symbol) const // While working on this example, we found fonts with no outlines for // printable characters such as `A', i.e., `outline.n_contours' and // `outline.n_points' were zero. FT_Outline_Check() returned `true'. -// FT_Outline_Decompose() also returned `true' without walking the outline. +// FT_Outline_Decompose() also returned `true' without walking the outline. // That is, we had no way of knowing whether the outline existed and could // be (or was) decomposed. Therefore, we implemented this workaround to // check whether the outline does exist and can be decomposed. bool OutlinePrinter::OutlineExists() const { - FT_Face face = m_face.m_ftFace; + FT_Face face = m_face; FT_GlyphSlot slot = face->glyph; FT_Outline &outline = slot->outline; @@ -243,6 +280,7 @@ OutlinePrinter::OutlineExists() const } +// This function flips outline around x-axis. We need it because // FreeType and SVG use opposite vertical directions. void OutlinePrinter::FlipOutline() const @@ -256,7 +294,7 @@ OutlinePrinter::FlipOutline() const matrix.yx = 0L * multiplier; matrix.yy = -1L * multiplier; - FT_Face face = m_face.m_ftFace; + FT_Face face = m_face; FT_GlyphSlot slot = face->glyph; FT_Outline &outline = slot->outline; @@ -279,7 +317,7 @@ OutlinePrinter::ExtractOutline() callbacks.shift = 0; callbacks.delta = 0; - FT_Face face = m_face.m_ftFace; + FT_Face face = m_face; FT_GlyphSlot slot = face->glyph; FT_Outline &outline = slot->outline; @@ -297,7 +335,7 @@ OutlinePrinter::ExtractOutline() void OutlinePrinter::ComputeViewBox() { - FT_Face face = m_face.m_ftFace; + FT_Face face = m_face; FT_GlyphSlot slot = face->glyph; FT_Outline &outline = slot->outline; diff --git a/freetype2/docs/tutorial/example5.svg b/freetype2/docs/tutorial/example5.svg index 78bad71..0034bf9 100644 --- a/freetype2/docs/tutorial/example5.svg +++ b/freetype2/docs/tutorial/example5.svg @@ -3,98 +3,58 @@ viewBox='107 -1364 1691 1753'> <path d=' M 1798 -752 - Q 1798 -649, 1769 -555 - Q 1741 -461, 1691 -380 - Q 1642 -300, 1574 -234 - Q 1506 -168, 1427 -121 - Q 1348 -75, 1260 -50 - Q 1173 -25, 1085 -25 - Q 1020 -25, 989 -59 - Q 959 -93, 957 -150 - Q 932 -129, 904 -106 - Q 877 -84, 844 -66 - Q 811 -48, 772 -36 - Q 734 -25, 686 -25 - Q 643 -25, 608 -43 - Q 574 -61, 550 -94 - Q 526 -128, 513 -175 - Q 500 -223, 500 -283 - Q 500 -353, 516 -426 - Q 533 -499, 566 -567 - Q 599 -636, 648 -697 - Q 698 -758, 764 -805 - Q 815 -842, 863 -865 - Q 912 -888, 962 -901 - Q 1013 -914, 1067 -919 - Q 1122 -924, 1184 -924 - Q 1232 -924, 1282 -920 - Q 1332 -917, 1367 -913 + Q 1798 -564, 1701 -396 + Q 1604 -229, 1437 -127 + Q 1270 -25, 1085 -25 + Q 961 -25, 957 -150 + L 905 -107 + Q 805 -25, 686 -25 + Q 600 -25, 550 -95 + Q 500 -165, 500 -283 + Q 500 -412, 551 -534 + Q 602 -657, 692 -745 + Q 783 -834, 895 -879 + Q 1007 -924, 1184 -924 + Q 1271 -924, 1367 -913 L 1246 -372 - Q 1241 -352, 1237 -330 - Q 1233 -308, 1230 -286 - Q 1227 -265, 1225 -246 - Q 1223 -227, 1223 -215 + Q 1237 -335, 1230 -285 + Q 1223 -235, 1223 -215 Q 1223 -192, 1231 -175 Q 1240 -159, 1273 -159 - Q 1326 -159, 1372 -183 - Q 1418 -208, 1456 -250 - Q 1494 -293, 1523 -350 - Q 1553 -407, 1573 -473 - Q 1593 -539, 1603 -610 - Q 1614 -681, 1614 -751 - Q 1614 -875, 1576 -970 - Q 1539 -1066, 1469 -1131 - Q 1399 -1196, 1300 -1229 - Q 1202 -1263, 1079 -1263 - Q 956 -1263, 850 -1230 - Q 744 -1198, 656 -1138 - Q 568 -1079, 500 -996 - Q 433 -914, 386 -814 - Q 339 -714, 315 -599 - Q 291 -485, 291 -363 - Q 291 -235, 327 -118 - Q 364 -1, 439 88 - Q 514 178, 627 231 - Q 741 284, 895 284 - Q 986 284, 1063 270 - Q 1141 256, 1207 232 - Q 1273 208, 1329 176 - Q 1386 144, 1436 109 + Q 1367 -159, 1445 -239 + Q 1523 -319, 1568 -459 + Q 1614 -599, 1614 -751 + Q 1614 -994, 1471 -1128 + Q 1329 -1263, 1079 -1263 + Q 853 -1263, 674 -1150 + Q 496 -1038, 393 -829 + Q 291 -621, 291 -363 + Q 291 -174, 364 -26 + Q 437 121, 573 202 + Q 710 284, 895 284 + Q 1042 284, 1171 244 + Q 1300 204, 1436 109 L 1480 173 - Q 1424 218, 1361 257 - Q 1298 296, 1223 325 - Q 1148 355, 1059 372 - Q 970 389, 864 389 - Q 680 389, 538 330 - Q 397 272, 301 170 - Q 205 68, 156 -69 - Q 107 -206, 107 -362 - Q 107 -505, 140 -635 - Q 173 -765, 234 -876 - Q 296 -987, 383 -1077 - Q 470 -1168, 578 -1231 - Q 687 -1295, 814 -1329 - Q 941 -1364, 1083 -1364 - Q 1261 -1364, 1395 -1320 - Q 1529 -1277, 1618 -1197 - Q 1708 -1117, 1753 -1004 - Q 1798 -891, 1798 -752 + Q 1338 287, 1189 338 + Q 1040 389, 864 389 + Q 636 389, 464 295 + Q 292 201, 199 29 + Q 107 -142, 107 -362 + Q 107 -648, 236 -879 + Q 365 -1110, 588 -1237 + Q 811 -1364, 1083 -1364 + Q 1424 -1364, 1611 -1203 + Q 1798 -1043, 1798 -752 M 740 -316 Q 740 -244, 761 -206 Q 783 -169, 811 -169 - Q 831 -169, 853 -175 - Q 875 -182, 896 -192 - Q 917 -202, 935 -214 - Q 953 -226, 965 -237 + Q 845 -169, 889 -189 + Q 934 -209, 965 -237 L 1085 -798 - Q 1078 -800, 1058 -801 - Q 1039 -803, 1024 -803 - Q 975 -803, 931 -789 - Q 888 -776, 852 -733 - Q 832 -709, 812 -666 - Q 792 -623, 776 -567 - Q 760 -512, 750 -447 - Q 740 -383, 740 -316 + Q 1068 -803, 1024 -803 + Q 922 -803, 868 -750 + Q 814 -698, 777 -571 + Q 740 -444, 740 -316 ' fill='red'/> </svg> diff --git a/freetype2/docs/tutorial/step3.html b/freetype2/docs/tutorial/step3.html index ca31b9b..44a566d 100644 --- a/freetype2/docs/tutorial/step3.html +++ b/freetype2/docs/tutorial/step3.html @@ -93,7 +93,7 @@ file</a> of the call</p> <pre> -example5 LiberationSerif-Bold.ttf @</pre> +example5 LiberationSerif-Bold.ttf @ > example5.cpp</pre> <p>(you can find the Liberation font family <a href="https://fedorahosted.org/liberation-fonts/">here</a>).</p> |