4#include "TGLIncludes.h"
10#include "TGLSdfFontMakerLowLevel.icxx"
23void gzip_compress_buffer(
const char *objbuf,
const size_t objlen, std::vector<char> &
result)
25 unsigned long objcrc = R__crc32(0, NULL, 0);
26 objcrc = R__crc32(objcrc, (
const unsigned char *)objbuf, objlen);
29 int buflen = 10 + objlen + 8;
35 char *bufcur =
result.data();
49 memcpy(dummy, bufcur - 6, 6);
52 unsigned long ziplen = R__memcompress(bufcur - 6, objlen + 6, (
char *)objbuf, objlen);
54 memcpy(bufcur - 6, dummy, 6);
56 bufcur += (ziplen - 6);
59 *bufcur++ = objcrc & 0xff;
60 *bufcur++ = (objcrc >> 8) & 0xff;
61 *bufcur++ = (objcrc >> 16) & 0xff;
62 *bufcur++ = (objcrc >> 24) & 0xff;
65 *bufcur++ = objlen & 0xff;
66 *bufcur++ = (objlen >> 8) & 0xff;
67 *bufcur++ = (objlen >> 16) & 0xff;
68 *bufcur++ = (objlen >> 24) & 0xff;
97 printf(
"TGLSdfFontMaker::MakeFont entering.\n");
99 const std::string base =
"31:126";
100 const std::string accented =
",0x00e0:0x00fc,0x010c:0x010d,0x0160:0x0161,0x017d:0x017e";
101 const std::string greek =
",0x0391:0x03a9,0x03b1:0x03c9";
102 const std::string range_end =
",0xffff";
104 root_sdf_fonts::SdfCreator sc;
107 std::unique_ptr<TGLWidget> glw(
111 glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &sc.max_tex_size);
114 std::string res_filename = output_prefix;
117 std::cerr <<
"Input file not specified" << std::endl;
121 if (res_filename.empty()) {
122 size_t ext_dot =
filename.find_last_of(
".");
123 if (ext_dot == std::string::npos) {
126 res_filename =
filename.substr(0, ext_dot);
130 if (!sc.font.load_ttf_file(
filename.c_str())) {
131 std::cerr <<
"Error reading TTF file '" <<
filename <<
"' " << std::endl;
137 sc.sdf_atlas.init(&sc.font, sc.width, sc.row_height, sc.border_size);
139 sc.parse_unicode_ranges(base + accented + greek + range_end);
140 sc.apply_unicode_ranges();
142 sc.sdf_atlas.draw_glyphs(sc.gp);
145 std::cout <<
"Allocated " << sc.sdf_atlas.glyph_count <<
" glyphs\n";
146 std::cout <<
"Atlas maximum height is " << sc.sdf_atlas.max_height <<
"\n";
149 if (sc.height == 0) {
150 sc.height = sc.sdf_atlas.max_height;
158 glGenRenderbuffers(1, &rbcolor);
159 glBindRenderbuffer(GL_RENDERBUFFER, rbcolor);
160 glRenderbufferStorage(GL_RENDERBUFFER, GL_RED, sc.width, sc.height);
161 glBindRenderbuffer(GL_RENDERBUFFER, 0);
164 glGenRenderbuffers(1, &rbds);
165 glBindRenderbuffer(GL_RENDERBUFFER, rbds);
166 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_STENCIL, sc.width, sc.height);
167 glBindRenderbuffer(GL_RENDERBUFFER, 0);
170 glGenFramebuffers(1, &fbo);
171 glBindFramebuffer(GL_FRAMEBUFFER, fbo);
172 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rbcolor);
173 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rbds);
175 if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
176 std::cerr <<
"Error creating framebuffer!" << std::endl;
182 uint8_t *picbuf = (uint8_t *)
malloc(sc.width * sc.height);
184 glViewport(0, 0, sc.width, sc.height);
185 glClearColor(0.0, 0.0, 0.0, 0.0);
186 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
188 sc.sdf_gl.render_sdf({float(sc.width), float(sc.height)}, sc.gp.fp.vertices, sc.gp.lp.vertices);
190 glReadPixels(0, 0, sc.width, sc.height, GL_RED, GL_UNSIGNED_BYTE, picbuf);
192 glBindFramebuffer(GL_FRAMEBUFFER, 0);
196 printf(
"Resulting GL buffer: w=%d, h=%d\n", sc.width, sc.height);
200 for (
int iy = 0; iy < sc.height; ++iy) {
210 std::string
json = sc.sdf_atlas.json(sc.height);
211 std::vector<char> json_gz;
212 gzip_compress_buffer(
json.data(),
json.size(), json_gz);
214 std::string json_filename = res_filename +
".js.gz";
215 FILE *json_file = fopen(json_filename.c_str(),
"wb");
217 perror(
"Error writing json file.");
220 fwrite(json_gz.data(), json_gz.size(), 1, json_file);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
C++ wrapper over simple writer of PNG files for standard GL memory formats: LUMINANCE,...
std::vector< unsigned char * > & ref_row_pointers()
int write_png_file(std::string_view filename)
static int MakeFont(const char *ttf_font, const char *output_prefix, bool verbose=false)
Converts TTF font 'ttf_font' into a SDF font texture atlas (png format) and a compressed font metrics...