Source/Gorgon/Graphics/FreeType.cpp

Thu, 17 Sep 2020 16:25:17 +0300

author
cemkalyoncu
date
Thu, 17 Sep 2020 16:25:17 +0300
branch
ComponentStackRework
changeset 1444
53e69f1cea46
parent 1376
e15204b22280
child 1451
8d05e766f523
permissions
-rwxr-xr-x

* Light hinting for better looking font

1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
1 #include "FreeType.h"
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
2
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
3 #include <set>
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
4
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
5 #include "Bitmap.h"
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
6 #include "../Filesystem.h"
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
7
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
8 #include <ft2build.h>
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
9 #include FT_FREETYPE_H
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
10
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
11 namespace {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
12 using namespace Gorgon::Graphics;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
13
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
14 Bitmap* fill_bitmap(FT_Face face, int index, bool aa,
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
15 FT_Vector *delta = nullptr, FT_Matrix *matrix = nullptr) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
16
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
17 if(delta || matrix)
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
18 FT_Set_Transform(face, matrix, delta);
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
19
1444
53e69f1cea46 * Light hinting for better looking font
cemkalyoncu
parents: 1376
diff changeset
20 auto error = FT_Load_Glyph(face, index, FT_LOAD_RENDER|(aa ? FT_LOAD_TARGET_LIGHT : FT_LOAD_MONOCHROME));
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
21
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
22 if(error != FT_Err_Ok)
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
23 return nullptr;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
24
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
25 auto slot = face->glyph;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
26 auto &ftbmp = slot->bitmap;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
27
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
28 auto &bmp = *new Bitmap(ftbmp.width, ftbmp.rows, ColorMode::Alpha);
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
29
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
30 if(ftbmp.pitch < 0) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
31 if(ftbmp.pixel_mode == FT_PIXEL_MODE_MONO) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
32 for(unsigned y=0; y<ftbmp.rows; y++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
33 int b = 7, B = 0; //bit, byte
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
34
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
35 for(unsigned x=0; x<ftbmp.width; x++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
36 bmp(x, ftbmp.rows - y - 1, 0) = ftbmp.buffer[B + y*ftbmp.pitch]&(1<<b) ? 255 : 0;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
37
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
38 b--;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
39 if(b<0) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
40 b = 7;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
41 B++;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
42 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
43 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
44 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
45 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
46 else {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
47 for(unsigned y=0; y<ftbmp.rows; y++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
48 for(unsigned x=0; x<ftbmp.width; x++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
49 bmp(x, ftbmp.rows - y - 1, 0) = ftbmp.buffer[x + y*ftbmp.pitch];
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
50 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
51 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
52 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
53 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
54 else {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
55 if(ftbmp.pixel_mode == FT_PIXEL_MODE_MONO) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
56 for(unsigned y=0; y<ftbmp.rows; y++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
57 int b = 7, B = 0; //bit, byte
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
58
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
59 for(unsigned x=0; x<ftbmp.width; x++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
60 bmp(x, y, 0) = ftbmp.buffer[B + y*ftbmp.pitch]&(1<<b) ? 255 : 0;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
61
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
62 b--;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
63 if(b<0) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
64 b = 7;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
65 B++;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
66 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
67 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
68 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
69 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
70 else {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
71 for(unsigned y=0; y<ftbmp.rows; y++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
72 for(unsigned x=0; x<ftbmp.width; x++) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
73 bmp(x, y, 0) = ftbmp.buffer[x + y*ftbmp.pitch];
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
74 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
75 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
76 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
77 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
78
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
79 return &bmp;
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
80 }
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
81 } // end of anonymous namespace
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
82
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
83 namespace Gorgon { namespace Graphics {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
84
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
85 struct ftlib {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
86 ftlib() {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
87 FT_Init_FreeType(&library);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
88 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
89
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
90 void destroyface() {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
91 if(face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
92 FT_Done_Face(face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
93
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
94 delete[] data;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
95
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
96 face = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
97 data = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
98
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
99 if(!vecdata.empty()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
100 std::vector<Byte> n;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
101 std::swap(vecdata, n);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
102 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
103 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
104
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
105 ~ftlib() {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
106 FT_Done_FreeType(library);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
107 library = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
108 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
109
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
110 FT_Library library;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
111 FT_Face face = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
112 std::vector<Byte> vecdata; //if we own our data
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
113 const Byte *data = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
114 };
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
115
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
116
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
117 FreeType::FreeType() : BasicFont(dynamic_cast<GlyphRenderer &>(*this)) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
118 lib = new ftlib;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
119 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
120
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
121 FreeType::~FreeType() {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
122 delete lib;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
123
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
124 destroylist.Destroy();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
125 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
126
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
127 bool FreeType::finalizeload() {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
128 isfixedw = (lib->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
129
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
130 //no unicode charmap table
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
131 if(lib->face->charmap == nullptr) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
132 auto error = FT_Select_Charmap(lib->face, FT_ENCODING_APPLE_ROMAN);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
133
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
134 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
135 error = FT_Select_Charmap(lib->face, FT_ENCODING_ADOBE_LATIN_1);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
136
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
137 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
138 error = FT_Select_Charmap(lib->face, FT_ENCODING_ADOBE_STANDARD);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
139
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
140 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
141 error = FT_Select_Charmap(lib->face, FT_ENCODING_ADOBE_EXPERT);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
142
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
143 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
144 error = FT_Select_Charmap(lib->face, FT_ENCODING_ADOBE_CUSTOM);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
146 if(error == FT_Err_Ok) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
147 isascii = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
148 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
149 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
150 error = FT_Select_Charmap(lib->face, FT_ENCODING_MS_SYMBOL);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
151
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
152 if(error == FT_Err_Ok) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
153 issymbol = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
154 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
155 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
156 if(lib->face->num_charmaps > 0) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
157 error = FT_Set_Charmap(lib->face, lib->face->charmaps[0]);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
158
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
159 isascii = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
160 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
161
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
162 if(error != FT_Err_Ok) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
163 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
164
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
165 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
166 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
167 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
168 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
169 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
170
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
171 haskerning = FT_HAS_KERNING(lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
172
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
173 filename = "";
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
174 vecdata = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
175 data = nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
176
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
177 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
178 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
179
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
180
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
181
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
182 bool FreeType::LoadFile(const std::string &filename) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
183 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
184
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
185 auto error = FT_New_Face(lib->library, filename.c_str(), 0, &lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
186
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
187 if(error != FT_Err_Ok || lib->face == nullptr)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
188 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
189
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
190 if(!finalizeload())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
191 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
192
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
193 this->filename = Filesystem::Canonical(filename);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
194
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
195 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
196 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
197
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
198
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
199 bool FreeType::LoadFile(const std::string &filename, int size, bool loadascii) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
200 if(!LoadFile(filename))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
201 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
202
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
203 if(!LoadMetrics(size))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
204 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
205
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
206 if(loadascii)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
207 return LoadGlyphs({0, {0x20, 0x7f}});
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
208 else
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
209 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
210 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
211
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
212
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
213 bool FreeType::Load(const std::vector<Byte> &data) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
214 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
215
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
216 auto error = FT_New_Memory_Face(lib->library, &data[0], (long)data.size(), 0, &lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
217
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
218 if(error != FT_Err_Ok || lib->face == nullptr)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
219 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
220
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
221 if(!finalizeload())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
222 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
223
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
224 vecdata = &data;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
225
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
226 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
227 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
228
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
229
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
230 bool FreeType::Load(const Byte *data, long datasize) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
231 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
232
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
233 auto error = FT_New_Memory_Face(lib->library, data, (long)datasize, 0, &lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
234
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
235 if(error != FT_Err_Ok || lib->face == nullptr)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
236 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
237
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
238 if(!finalizeload())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
239 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
240
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
241 this->data = data;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
242 this->datasize = datasize;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
243
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
244 return true;
1141
8e5473c0745d * Saving FreeType as resource
cemkalyoncu
parents: 1140
diff changeset
245 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
246
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
247
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
248 bool FreeType::Assume(std::vector<Byte> &data) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
249 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
250
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
251 std::swap(lib->vecdata, data);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
252
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
253 auto error = FT_New_Memory_Face(lib->library, &lib->vecdata[0], (long)lib->vecdata.size(), 0, &lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
254
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
255 if(error != FT_Err_Ok || lib->face == nullptr)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
256 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
257
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
258 if(!finalizeload())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
259 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
260
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
261 this->vecdata = &lib->vecdata;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
262
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
263 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
264 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
265
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
266
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
267 bool FreeType::Assume(const Byte *data, long datasize) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
268 lib->destroyface();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
269
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
270 lib->data = data;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
271
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
272 auto error = FT_New_Memory_Face(lib->library, data, datasize, 0, &lib->face);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
273
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
274 if(error != FT_Err_Ok || lib->face == nullptr)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
275 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
276
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
277 if(!finalizeload())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
278 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
279
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
280 this->data = data;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
281 this->datasize = datasize;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
282
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
283 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
284 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
285
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
286
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
287 bool FreeType::savedata(std::ostream &stream) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
288 if(!vecdata && !data && filename == "")
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
289 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
290
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
291 if(vecdata)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
292 IO::WriteVector(stream, *vecdata);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
293 else if(data)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
294 IO::WriteArray(stream, data, datasize);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
295 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
296 std::ifstream file(filename, std::ios::binary);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
297
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
298 if(!file.is_open())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
299 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
300
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
301 char buffer[1024];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
302 while(!file.read(buffer, 1024).bad()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
303 if(file.gcount() <= 0)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
304 break;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
305
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
306 IO::WriteArray(stream, buffer, (unsigned long)file.gcount());
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
307 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
308 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
309
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
310 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
311 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
312
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
313
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
314 bool FreeType::LoadMetrics(int size) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
315 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
316 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
317
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
318 if(IsScalable()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
319 auto error = FT_Set_Pixel_Sizes(lib->face, 0, size);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
320
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
321 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
322 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
323
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
324 auto xscale = lib->face->size->metrics.x_scale;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
325 auto yscale = lib->face->size->metrics.y_scale;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
326
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
327 maxadvance = (int)std::round(FT_MulFix(lib->face->bbox.xMax, xscale)/64.f);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
328 maxwidth = (int)std::round(FT_MulFix((lib->face->bbox.xMax-lib->face->bbox.xMin), xscale)/64.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
329 height = (int)std::round(FT_MulFix((lib->face->bbox.yMax-lib->face->bbox.yMin), yscale)/64.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
330
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
331 baseline = std::round(lib->face->size->metrics.ascender/64.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
332
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
333 linegap = std::round(lib->face->size->metrics.height/64.f);
1372
d3449b82e33d #122: Smoothed borders
cemkalyoncu
parents: 1368
diff changeset
334
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
335 underlinepos = (int)std::round(baseline - FT_MulFix((lib->face->underline_position),yscale)/64.f);
1372
d3449b82e33d #122: Smoothed borders
cemkalyoncu
parents: 1368
diff changeset
336 linethickness = FT_MulFix((lib->face->underline_thickness),yscale)/64.f;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
337 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
338 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
339 //search bitmap size table and find values that is closest to the given one.
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
340
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
341 int mindiff = INT_MAX;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
342 int minind = -1;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
343
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
344 for(int i=0; i<lib->face->num_fixed_sizes; i++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
345 auto s = lib->face->available_sizes[i];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
346 auto diff = abs(s.height - size);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
347
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
348 if(diff < mindiff) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
349 mindiff = diff;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
350 minind = i;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
351 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
352 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
353
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
354 if(minind == -1)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
355 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
356
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
357 auto s = lib->face->available_sizes[minind];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
358
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
359 auto error = FT_Set_Pixel_Sizes(lib->face, s.width, s.height);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
360
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
361 if(error != FT_Err_Ok)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
362 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
363
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
364 baseline = std::round(lib->face->size->metrics.ascender/64.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
365
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
366 maxwidth = s.width;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
367 height = s.height;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
368
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
369 underlinepos = (int)std::round((baseline + height) / 2.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
370
1376
e15204b22280 * Readonly support for Inputbox
cemkalyoncu
parents: 1372
diff changeset
371 linethickness = (float)height / 10;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
372
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
373 linegap = std::round(lib->face->size->metrics.height/64.f);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
374
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
375 if(linethickness < 1) linethickness = 1;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
376 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
377
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
378 this->size = (float)size;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
379 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
380 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
381
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
382
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
383 bool FreeType::loadglyphs(GlyphRange range, bool prepare) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
384 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
385 return false;
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
386
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
387 auto slot = lib->face->glyph;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
388
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
389 int done = 0;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
390 for(Glyph g = range.Start; g <= range.End; g++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
391 done++; //already loaded glyphs are also counted as done
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
392
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
393 //we already have this glyph
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
394 if(glyphmap.count(g)) continue;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
395
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
396 auto index = FT_Get_Char_Index(lib->face, g);
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
397
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
398 //check if glyph is already loaded. if so use the same
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
399 if(ft_to_map.count(index) && glyphmap.count(ft_to_map[index])) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
400 glyphmap[g] = glyphmap[ft_to_map[index]];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
401 continue;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
402 }
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
403
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
404 auto bmp = fill_bitmap(lib->face, index, aa);
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
405 FT_Vector penpos = {32 /* 0.5 * 64 */, 0};
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
406 auto withoffset = fill_bitmap(lib->face, index, aa, &penpos);
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
407
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
408 if(!bmp || !withoffset) {
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
409 if(range.Count() > 1) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
410 //error, this one is not done
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
411 done--;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
412 continue;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
413 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
414 else
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
415 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
416 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
417
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
418 destroylist.Add(*bmp);
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
419 destroylist.Add(*withoffset);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
420
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
421 glyphmap[g] = {{bmp, withoffset},
1269
a2216486f266 * use fractional advance value instead of rounded one
cengizkandemir
parents: 1268
diff changeset
422 slot->linearHoriAdvance/float(1<<16),
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
423 {(int)slot->bitmap_left, (int)-slot->bitmap_top},
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
424 (unsigned int)index};
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
425 ft_to_map[index] = g;
1141
8e5473c0745d * Saving FreeType as resource
cemkalyoncu
parents: 1140
diff changeset
426
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
427 if(g < 127 && isdigit(g) && digw < bmp->GetWidth())
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
428 digw = bmp->GetWidth();
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
429
1268
af3ae16e0b4a * prepare bitmap with offset as well
cengizkandemir
parents: 1267
diff changeset
430 if(prepare) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
431 bmp->Prepare();
1268
af3ae16e0b4a * prepare bitmap with offset as well
cengizkandemir
parents: 1267
diff changeset
432 withoffset->Prepare();
af3ae16e0b4a * prepare bitmap with offset as well
cengizkandemir
parents: 1267
diff changeset
433 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
434 }
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
435
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
436 return done > 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
437 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
438
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
439
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
440 bool FreeType::IsScalable() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
441 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
442 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
443
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
444 return (lib->face->face_flags & FT_FACE_FLAG_SCALABLE) != 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
445 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
446
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
447
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
448 std::vector<int> FreeType::GetPresetSizes() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
449 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
450 return {};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
451
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
452 std::vector<int> ret;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
453 ret.reserve(lib->face->num_fixed_sizes);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
454
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
455 for(int i=0; i<lib->face->num_fixed_sizes; i++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
456 ret.push_back(lib->face->available_sizes[i].height);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
457 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
458
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
459 return ret;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
460 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
461
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
462
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
463 std::string FreeType::GetFamilyName() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
464 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
465 return {};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
466
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
467 return lib->face->family_name;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
468 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
469
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
470
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
471 std::string FreeType::GetStyleName() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
472 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
473 return {};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
474
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
475 return lib->face->style_name;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
476 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
477
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
478
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
479 bool FreeType::IsFileLoaded() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
480 return lib->face != nullptr;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
481 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
482
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
483
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
484 bool FreeType::IsReady() const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
485 return height != 0 && (lib->face != nullptr || !glyphmap.empty());
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
486 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
487
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
488 Geometry::Size FreeType::GetSize(Glyph chr) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
489 if(glyphmap.count(chr))
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
490 return glyphmap.at(chr).images.regular->GetSize();
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
491 else if(glyphmap.count(0) && !internal::isspace(chr) && !internal::isnewline(chr) && chr != '\t')
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
492 return glyphmap.at(0).images.regular->GetSize();
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
493 else
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
494 return{0, 0};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
495 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
496
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
497 float FreeType::GetCursorAdvance(Glyph chr) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
498 if(glyphmap.count(chr))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
499 return glyphmap.at(chr).advance;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
500 else if(chr == '\t')
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
501 return (float)height;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
502 else if(internal::isspace(chr))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
503 return float(height / 4);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
504 else if(glyphmap.count(0))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
505 return glyphmap.at(0).advance;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
506 else
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
507 return 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
508 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
509
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
510 bool FreeType::Exists(Glyph g) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
511 return glyphmap.count(g);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
512 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
513
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
514 bool FreeType::Available(Glyph g) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
515 if(glyphmap.count(g))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
516 return true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
517
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
518 if(!lib->face)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
519 return false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
520
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
521 return FT_Get_Char_Index(lib->face, g) != 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
522 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
523
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
524 void FreeType::Render(Glyph chr, TextureTarget &target, Geometry::Pointf location, RGBAf color) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
525 if(glyphmap.count(chr)) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
526 auto glyph = glyphmap.at(chr);
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
527 glyph.images.regular->Draw(target, location + glyph.offset + Geometry::Pointf(0.f, (float)baseline), color);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
528 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
529 else if(glyphmap.count(0) && !internal::isspace(chr) && !internal::isnewline(chr) && chr != '\t') {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
530 auto glyph = glyphmap.at(0);
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
531 glyph.images.regular->Draw(target, location + glyph.offset + Geometry::Pointf(0.f, (float)baseline), color);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
532 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
533 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
534
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
535 Geometry::Pointf FreeType::KerningDistance(Glyph chr1, Glyph chr2) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
536 if(!lib->face || !haskerning || !glyphmap.count(chr1) || !glyphmap.count(chr2))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
537 return {0.f, 0.f};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
538
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
539 FT_Vector p;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
540 FT_Get_Kerning(lib->face, glyphmap.at(chr1).ftindex, glyphmap.at(chr2).ftindex, FT_KERNING_DEFAULT, &p);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
541
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
542 if(p.x != 0)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
543 p.x = p.x;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
544
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
545 return {std::round(p.x / 64.f), std::round(p.y / 64.f)};
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
546 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
547
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
548 void FreeType::Prepare(const std::string& text) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
549 std::set<Glyph> list;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
550
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
551 for(auto it=text.begin(); it!=text.end(); it++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
552 auto g = internal::decode(it, text.end());
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
553 if(!Exists(g))
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
554 list.insert(g);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
555 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
556
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
557 auto it = list.begin();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
558 auto prev = list.begin();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
559
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
560 std::vector<GlyphRange> ranges;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
561
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
562 while(it != list.end()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
563 it = std::adjacent_find(it, list.end(), [](int l, int r) { return l+1<r; });
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
564
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
565 if(it == list.end()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
566 ranges.push_back({*prev, *list.rbegin()});
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
567 break;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
568 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
569 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
570 ranges.push_back({*prev, *(it)});
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
571 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
572
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
573 it++;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
574 prev = it;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
575 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
576
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
577 for(auto &range : ranges)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
578 loadglyphs(range, true);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
579
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
580 if(keeppacked)
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
581 pack();
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
582 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
583
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
584
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
585 BitmapFont FreeType::CopyToBitmap(bool prepare) const {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
586 BitmapFont font;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
587
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
588 //determine glyph spacing
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
589 GlyphDescriptor d;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
590 int gs = int(GetHeight() / 10);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
591
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
592 if(glyphmap.count('0') && glyphmap['0'].advance != 0 && glyphmap['0'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
593 d = glyphmap['0'];
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
594 else if(glyphmap.count('A') && glyphmap['A'].advance != 0 && glyphmap['A'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
595 d = glyphmap['A'];
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
596 else if(glyphmap.count('_') && glyphmap['_'].advance != 0 && glyphmap['_'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
597 d = glyphmap['_'];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
598
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
599 if(d.advance != 0 && d.images.regular != nullptr)
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
600 gs = (int)std::round(d.advance - d.images.regular->GetWidth() + glyphmap['0'].offset.X);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
601
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
602 if(gs < 1)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
603 gs = 1;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
604
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
605 font.SetBaseline(baseline);
1376
e15204b22280 * Readonly support for Inputbox
cemkalyoncu
parents: 1372
diff changeset
606 font.SetLineThickness((int)std::round(linethickness));
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
607 font.SetUnderlineOffset(underlinepos);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
608 font.SetLineGap(linegap);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
609 font.SetGlyphSpacing(gs);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
610
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
611 //copy kerning table
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
612 if(haskerning) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
613 for(auto &l : glyphmap) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
614 for(auto &r : glyphmap) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
615 auto p = KerningDistance(l.first, r.first);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
616
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
617 if(p.X != 0 || p.Y != 0) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
618 font.SetKerning(l.first, r.first, p);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
619 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
620 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
621 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
622 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
623
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
624 std::map<const RectangularDrawable*, Bitmap*> newmapping;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
625
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
626 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
627 if(!newmapping.count(g.second.images.regular)) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
628 if(dynamic_cast<const Bitmap*>(g.second.images.regular)) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
629 auto img = dynamic_cast<const Bitmap*>(g.second.images.regular);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
630
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
631 newmapping[img] = new Bitmap(img->Duplicate());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
632
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
633 if(prepare)
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
634 newmapping[img]->Prepare();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
635 }
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
636 else if(dynamic_cast<const TextureImage*>(g.second.images.regular) && atlasdata.GetTotalSize() > 0 &&
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
637 dynamic_cast<const TextureImage*>(g.second.images.regular)->GetID() == atlas.GetID()) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
638 auto img = dynamic_cast<const TextureImage*>(g.second.images.regular);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
639
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
640 //create a new bitmap
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
641 auto bmp = new Bitmap(g.second.images.regular->GetSize(), atlasdata.GetMode());
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
642
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
643 //copy atlas data back to it
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
644 auto c = img->GetCoordinates();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
645 int left = (int)std::round(c[0].X * atlasdata.GetWidth());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
646 int right = (int)std::round(c[2].X * atlasdata.GetWidth());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
647 int top = (int)std::round(c[0].Y * atlasdata.GetHeight());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
648 int bottom = (int)std::round(c[2].Y * atlasdata.GetHeight());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
649
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
650 atlasdata.CopyTo(bmp->GetData(), {left, top, right, bottom});
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
651 if(prepare)
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
652 bmp->Prepare();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
653
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
654 newmapping.insert({img, bmp});
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
655 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
656 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
657
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
658 if(newmapping.count(g.second.images.regular)) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
659 font.AssumeGlyph(g.first, *newmapping[g.second.images.regular], g.second.offset + Geometry::Pointf(0, baseline), g.second.advance);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
660 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
661 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
662
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
663 return font;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
664 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
665
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
666
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
667 BitmapFont FreeType::MoveOutBitmap(bool unpack, bool prepare) {
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
668 BitmapFont font;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
669
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
670 //determine glyph spacing
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
671 GlyphDescriptor d;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
672 int gs = int(GetHeight() / 10);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
673
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
674 if(glyphmap.count('0') && glyphmap['0'].advance != 0 && glyphmap['0'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
675 d = glyphmap['0'];
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
676 else if(glyphmap.count('A') && glyphmap['A'].advance != 0 && glyphmap['A'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
677 d = glyphmap['A'];
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
678 else if(glyphmap.count('_') && glyphmap['_'].advance != 0 && glyphmap['_'].images.regular != nullptr)
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
679 d = glyphmap['_'];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
680
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
681 if(d.advance != 0 && d.images.regular != nullptr)
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
682 gs = (int)std::round(d.advance - d.images.regular->GetWidth() + glyphmap['0'].offset.X);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
683
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
684 if(gs < 1)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
685 gs = 1;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
686
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
687 font.SetBaseline(baseline);
1376
e15204b22280 * Readonly support for Inputbox
cemkalyoncu
parents: 1372
diff changeset
688 font.SetLineThickness((int)std::round(linethickness));
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
689 font.SetUnderlineOffset(underlinepos);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
690 font.SetLineGap(linegap);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
691 font.SetGlyphSpacing(gs);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
692
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
693 //copy kerning table
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
694 if(haskerning) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
695 for(auto &l : glyphmap) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
696 for(auto &r : glyphmap) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
697 auto p = KerningDistance(l.first, r.first);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
698
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
699 if(p.X != 0 || p.Y != 0) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
700 font.SetKerning(l.first, r.first, p);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
701 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
702 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
703 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
704 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
705
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
706 //if there is no atlasdata, there is no way or reason to unpack
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
707 if(unpack && atlasdata.GetTotalSize() != 0) {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
708 std::map<const RectangularDrawable*, Bitmap *> map;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
709
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
710 for(auto &g : glyphmap) {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
711 // already bitmap no need to do anything
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
712 if(dynamic_cast<const Bitmap*>(g.second.images.regular)) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
713 font.AddGlyph(g.first, *g.second.images.regular, g.second.offset + Geometry::Pointf(0, baseline), g.second.advance);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
714 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
715 else {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
716 //just to be sure
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
717 auto img = dynamic_cast<const TextureImage*>(g.second.images.regular);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
718
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
719 //if the glyph is not transformed and can be transformed
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
720 if(!map.count(g.second.images.regular) && img && img->GetID() == atlas.GetID()) {
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
721 //create a new bitmap
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
722 auto bmp = new Bitmap(g.second.images.regular->GetSize(), atlasdata.GetMode());
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
723
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
724 font.Adopt(*bmp);
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
725
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
726 //copy atlas data back to it
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
727 auto c = img->GetCoordinates();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
728 int left = (int)std::round(c[0].X * atlasdata.GetWidth());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
729 int right = (int)std::round(c[2].X * atlasdata.GetWidth());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
730 int top = (int)std::round(c[0].Y * atlasdata.GetHeight());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
731 int bottom = (int)std::round(c[2].Y * atlasdata.GetHeight());
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
732
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
733 atlasdata.CopyTo(bmp->GetData(), {left, top, right, bottom}, {0, 0});
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
734 if(prepare)
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
735 bmp->Prepare();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
736
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
737 map.insert({img, bmp});
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
738
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
739 delete img;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
740 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
741
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
742 if(map.count(g.second.images.regular)) {
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
743 font.AddGlyph(g.first, *map[g.second.images.regular], g.second.offset + Geometry::Pointf(0, baseline), g.second.advance);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
744 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
745 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
746 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
747 }
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
748 else {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
749 //add glpyhs
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
750 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
751 font.AddGlyph(g.first, *g.second.images.regular, g.second.offset + Geometry::Pointf(0, baseline), g.second.advance);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
752 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
753
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
754 //transfer ownership
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
755 for(const auto &i : destroylist) {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
756 font.Adopt(i);
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
757 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
758
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
759 //if we have atlas
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
760 if(atlas.GetID()) {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
761 //adopt and release it
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
762 font.Adopt(*new TextureImage(atlas.GetID(), atlas.GetMode(), atlas.GetImageSize()));
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
763 atlas.Release();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
764 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
765 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
766
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
767 //clear to ensure they wont be destroyed
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
768 destroylist.Clear();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
769
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
770 Clear();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
771
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
772 return font;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
773 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
774
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
775
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
776 void FreeType::Clear(){
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
777 glyphmap.clear();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
778 destroylist.DeleteAll();
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
779
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
780 atlasdata.Destroy();
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
781
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
782 std::vector<bool> e;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
783 std::swap(used, e);
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
784 rowsused = 0;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
785
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
786 digw = 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
787 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
788
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
789
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
790 void FreeType::setatlassize(unsigned size) const {
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
791 if(size < 1) return;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
792
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
793 int w = CeilToPowerOf2(unsigned(sqrt(float(size))));
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
794 int h = CeilToPowerOf2((int)ceil(size / w));
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
795
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
796 if(atlas.GetID()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
797 //resize and copy everything
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
798
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
799 std::vector<bool> nu(w*h);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
800 int ow = atlasdata.GetWidth(), oh = atlasdata.GetHeight();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
801 for(int y=0; y<oh; y++)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
802 for(int x=0; x<ow; x++)
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
803 nu[y*w+x] = used[y*ow+x];
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
804
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
805 std::swap(used, nu);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
806
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
807 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
808 if(g.second.images.regular && dynamic_cast<const TextureImage*>(g.second.images.regular)) {
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
809 //cast away constness, we need to update them as their base is modified
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
810 auto im = dynamic_cast<TextureImage*>(g.second.images.regular);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
811 auto c = im->GetCoordinates();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
812
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
813 int l = (int)std::round(c[0].X*ow);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
814 int t = (int)std::round(c[0].Y*oh);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
815 int r = (int)std::round(c[2].X*ow);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
816 int b = (int)std::round(c[2].Y*oh);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
817
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
818 im->Set(im->GetID(), im->GetMode(), {w, h}, {l, t, r, b});
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
819 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
820 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
821
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
822
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
823 Containers::Image ni({w, h}, ColorMode::Alpha);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
824 atlasdata.CopyTo(ni, {0, 0});
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
825 atlasdata.Swap(ni);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
826
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
827 GL::UpdateTexture(atlas.GetID(), atlasdata);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
828 atlas.Set(atlas.GetID(), atlas.GetMode(), {w, h});
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
829 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
830 else {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
831 used.resize(w*h);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
832 atlas.CreateEmpty({w, h}, ColorMode::Alpha);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
833 atlasdata.Resize ({w, h}, ColorMode::Alpha);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
834 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
835 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
836
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
837
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
838 void FreeType::pack(float extrasize) const {
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
839 int cursize = 0;
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
840 bool cpeach = true;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
841 if(atlas.GetID()) {
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
842 cursize = rowsused * atlas.GetImageSize().Width;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
843 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
844
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
845 //collect images
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
846 Containers::Collection<const Bitmap> images;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
847 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
848 if(dynamic_cast<const Bitmap*>(g.second.images.regular))
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
849 images.Add(dynamic_cast<const Bitmap*>(g.second.images.regular));
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
850 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
851
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
852 if(images.GetSize() == 0)
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
853 return;
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
854
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
855 //determine collective size, add 2% extra for inefficiency
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
856 //of packing
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
857 for(auto &i : images) {
1148
ec4d336f571a * Visual studio fixes
cemkalyoncu
parents: 1147
diff changeset
858 cursize += (int)ceil(i.GetSize().Area() * 1.2 + (tightpack ? 0 : i.GetWidth() + i.GetHeight()));
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
859 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
860
1192
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
861 //Copying each image separately is not working properly, thus it is disabled for now
66e0a8012402 * Animation governor that allows controlling animation controllers
cemkalyoncu
parents: 1152
diff changeset
862 //if(images.GetCount() > 5)
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
863 cpeach = false;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
864
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
865 if(atlas.GetID()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
866 if(cursize > atlas.GetImageSize().Area()) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
867 //enlarge for future glyphs
1148
ec4d336f571a * Visual studio fixes
cemkalyoncu
parents: 1147
diff changeset
868 cursize = (int)std::ceil(cursize * (1 + extrasize));
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
869
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
870 setatlassize(cursize);
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
871 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
872 }
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
873 else {
1148
ec4d336f571a * Visual studio fixes
cemkalyoncu
parents: 1147
diff changeset
874 cursize = (int)std::ceil(cursize * (1 + extrasize));
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
875
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
876 setatlassize(cursize);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
877 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
878
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
879 //sort by height then width
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
880 images.Sort([](const Bitmap &l, const Bitmap &r) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
881 if(l.GetHeight() == r.GetHeight())
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
882 return l.GetWidth() < r.GetWidth();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
883 else
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
884 return l.GetHeight() < r.GetHeight();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
885 });
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
886
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
887 auto aw = atlasdata.GetWidth(), ah = atlasdata.GetHeight();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
888
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
889 std::map<const RectangularDrawable *, TextureImage *> replacements;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
890
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
891 //this is not the best algorithm for the job, but it gets the deed done
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
892 for(auto &b : images) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
893 retry:
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
894 Geometry::Point cur = {0, 0};
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
895
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
896 auto w = b.GetWidth(), h = b.GetHeight();
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
897
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
898 if(!tightpack) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
899 w++;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
900 h++;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
901 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
902
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
903 bool found = false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
904 while(!found) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
905 //run out of width, start over from the next row
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
906 if(cur.X + w > aw) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
907 cur.Y++;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
908 cur.X = 0;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
909 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
910
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
911 //run out of space, resize and retry
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
912 if(cur.Y + h > ah) {
1148
ec4d336f571a * Visual studio fixes
cemkalyoncu
parents: 1147
diff changeset
913 cursize = (int)std::ceil(cursize * 1.2);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
914 setatlassize(cursize);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
915
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
916 for(auto &img : replacements) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
917 auto im = img.second;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
918 auto c = im->GetCoordinates();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
919
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
920 int l = (int)std::round(c[0].X*aw);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
921 int t = (int)std::round(c[0].Y*ah);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
922 int r = (int)std::round(c[2].X*aw);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
923 int b = (int)std::round(c[2].Y*ah);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
924 im->Set(im->GetID(), im->GetMode(), atlasdata.GetSize(), {l, t, r, b});
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
925 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
926 aw = atlasdata.GetWidth();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
927 ah = atlasdata.GetHeight();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
928
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
929
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
930 goto retry;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
931 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
932
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
933 bool full = false;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
934 //check horizontal free
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
935 for(int x=cur.X; x<cur.X+w; x++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
936 if(used[x + cur.Y * aw]) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
937 full = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
938 break;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
939 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
940 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
941
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
942 if(full) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
943 cur.X++;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
944 continue;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
945 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
946
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
947 //check vertical free
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
948 for(int y=cur.Y; y<cur.Y+h; y++) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
949 if(used[cur.X + y * aw]) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
950 full = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
951 break;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
952 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
953 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
954
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
955 if(full) {
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
956 cur.X++;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
957 continue;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
958 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
959
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
960 for(int y=cur.Y; y<cur.Y+h; y++) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
961 for(int x=cur.X; x<cur.X+w; x++) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
962 used[x+y*aw] = true;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
963 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
964 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
965
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
966 //found our place
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
967 b.GetData().CopyTo(atlasdata, cur);
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
968 if(cpeach) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
969 GL::CopyToTexture(atlas.GetID(), b.GetData(), cur);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
970 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
971
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
972 auto tex = new TextureImage(atlas.GetID(), ColorMode::Alpha, atlas.GetImageSize(), {cur, b.GetSize()});
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
973
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
974 if(cur.Y + h > rowsused)
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
975 rowsused = cur.Y + h;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
976
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
977 replacements.insert({&b, tex});
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
978
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
979 destroylist.Add(tex);
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
980
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
981 found = true;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
982 }
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
983
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
984 if(!found) //useless
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
985 return;
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
986 }
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
987
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
988 if(!cpeach) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
989 GL::UpdateTexture(atlas.GetID(), atlasdata);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
990 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
991
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
992 //to test if the atlas is good
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
993 //Bitmap ad;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
994 //ad.Assign(atlasdata);
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
995 //ad.ExportPNG("test.png");
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
996
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
997 //replace images
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
998 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
999 if(replacements.count(g.second.images.regular))
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
1000 g.second.images.regular = replacements[g.second.images.regular];
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1001 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1002
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1003 //destroy old images
1262
ece284e57b34 * Focus prevention strategy
cemkalyoncu
parents: 1192
diff changeset
1004 for(auto &im : images) {
ece284e57b34 * Focus prevention strategy
cemkalyoncu
parents: 1192
diff changeset
1005 destroylist.Remove(im);
ece284e57b34 * Focus prevention strategy
cemkalyoncu
parents: 1192
diff changeset
1006 }
1146
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1007 images.Destroy();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1008 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1009
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1010 bool FreeType::LoadGlyphs(const std::vector< Gorgon::Graphics::GlyphRange >& ranges, bool prepare) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1011 for(auto r : ranges) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1012 if(!loadglyphs(r, prepare))
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1013 return false;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1014 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1015
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1016 if(keeppacked)
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1017 pack();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1018
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1019 return true;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1020 }
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1021
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1022 bool FreeType::LoadGlyphs(GlyphRange range, bool prepare) {
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1023 if(!loadglyphs(range, prepare))
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1024 return false;
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1025
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1026 if(keeppacked)
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1027 pack();
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1028
e5c5b0d1302f * Packing is completed
cemkalyoncu
parents: 1145
diff changeset
1029 return true;
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
1030 }
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1031
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1032 void FreeType::Discard() {
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1033 atlasdata.Destroy();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1034
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1035 for(auto &g : glyphmap) {
1267
6ec44d15f8a9 * render and store two font bitmaps, one regular one with a slight (0.5px) offset
cengiz.kandemir
parents: 1262
diff changeset
1036 auto bmp = dynamic_cast<Bitmap*>(g.second.images.regular);
1147
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1037
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1038 if(bmp)
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1039 bmp->Discard();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1040 }
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1041
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1042 lib->destroyface();
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1043 filename = "";
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1044 vecdata = nullptr;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1045 data = nullptr;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1046 datasize = 0;
caee0524b721 * Unpacking support while exporting bitmap font
cemkalyoncu
parents: 1146
diff changeset
1047 }
1368
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1048
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1049 std::pair<int, int> FreeType::GetLetterHeight(bool asciionly) const {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1050 Char c[3];
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1051
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1052 if(asciionly) {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1053 c[0] = 'A';
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1054
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1055 loadglyphs('A', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1056 loadglyphs('f', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1057 loadglyphs('j', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1058 }
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1059 else {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1060 loadglyphs('A', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1061 loadglyphs(0xc2, true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1062 loadglyphs('f', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1063 loadglyphs('j', true);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1064
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1065 if(glyphmap.count(0xc2)) {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1066 c[0] = 0xc2;
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1067 }
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1068 else
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1069 c[0] = 'A';
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1070 }
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1071 c[1] = 'j';
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1072 c[2] = 'f';
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1073
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1074 for(int i = 0; i<3; i++) {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1075 if(!glyphmap.count(c[i]) && !glyphmap.at(c[i]).images.regular)
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1076 return {0, GetHeight()};
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1077 }
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1078
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1079 int miny = GetHeight(), maxy = 0;
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1080
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1081 for(int i = 0; i<3; i++) {
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1082 const auto &g = glyphmap.at(c[i]);
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1083
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1084 //we trust freetype to give us trimmed images
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1085
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1086 if(g.offset.Y < miny)
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1087 miny = g.offset.Y;
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1088
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1089 if(g.offset.Y + g.images.regular->GetHeight() > maxy)
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1090 maxy = g.offset.Y + g.images.regular->GetHeight();
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1091 }
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1092
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1093 return {miny + baseline, maxy - miny};
9135822b5605 * Letter size for fonts
cemkalyoncu
parents: 1269
diff changeset
1094 }
1145
8811db395c77 * Packing algorithm is almost done
cemkalyoncu
parents: 1144
diff changeset
1095 } }

mercurial