}
}
+/**
+ * Parse an SVG string into a rectangle
+ */
+void Document::ParseSVG(const string & input, const Rect & bounds)
+{
+ using namespace pugi;
+
+ xml_document doc_xml;
+ xml_parse_result result = doc_xml.load(input.c_str());
+
+ if (!result)
+ Error("Couldn't parse SVG input - %s", result.description());
+
+ Debug("Loaded XML - %s", result.description());
+ SVGMatrix transform = {bounds.w, 0,bounds.x, 0,bounds.h,bounds.y};
+ ParseSVGNode(doc_xml, transform);
+}
+
/**
* Load an SVG into a rectangle
*/
xml_parse_result result = doc_xml.load(input);
if (!result)
- Fatal("Couldn't load \"%s\" - %s", filename.c_str(), result.description());
+ Error("Couldn't load \"%s\" - %s", filename.c_str(), result.description());
Debug("Loaded XML - %s", result.description());
free(m_font_data);
}
- FILE *font_file = fopen("DejaVuSansMono.ttf", "rb");
+ FILE *font_file = fopen(font_filename.c_str(), "rb");
fseek(font_file, 0, SEEK_END);
size_t font_file_size = ftell(font_file);
fseek(font_file, 0, SEEK_SET);
return;
}
- float font_scale = stbtt_ScaleForPixelHeight(&m_font, scale);
Real x0(x);
//Real y0(y);
int ascent = 0, descent = 0, line_gap = 0;
stbtt_GetFontVMetrics(&m_font, &ascent, &descent, &line_gap);
+ float font_scale = scale / (float)(ascent - descent);
Real y_advance = Real(font_scale) * Real(ascent - descent + line_gap);
for (unsigned i = 0; i < text.size(); ++i)
{
int advance_width = 0, left_side_bearing = 0, kerning = 0;
stbtt_GetCodepointHMetrics(&m_font, text[i], &advance_width, &left_side_bearing);
- if (i > 1)
+ if (i >= 1)
{
kerning = stbtt_GetCodepointKernAdvance(&m_font, text[i-1], text[i]);
}
- x += Real(font_scale) * Real(left_side_bearing + kerning);
+ x += Real(font_scale) * Real(kerning);
AddFontGlyphAtPoint(&m_font, text[i], font_scale, x, y);
x += Real(font_scale) * Real(advance_width);
}
{
AddGroup(start_index, end_index);
}
+ Debug("Added Glyph \"%c\" at %f %f, scale %f", (char)character, Float(x), Float(y), Float(scale));
stbtt_FreeShape(font, instructions);
}