Go nuts with Qt
[ipdf/code.git] / src / document.cpp
index 16cb8f9..e0dd70b 100644 (file)
@@ -130,6 +130,8 @@ int Document::ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type)
                m_objects.data_indices.push_back(m_objects.data_indices[object_id]);
                return 1;
                }
+       case GROUP:
+               break;
        default:
                Debug("Adding %s -> %s", m_objects.bounds[object_id].Str().c_str(), TransformToQuadChild(m_objects.bounds[object_id], type).Str().c_str());
                m_objects.bounds.push_back(TransformToQuadChild(m_objects.bounds[object_id], type));
@@ -543,6 +545,24 @@ void Document::ParseSVGNode(pugi::xml_node & root, SVGMatrix & parent_transform)
        }
 }
 
+/**
+ * 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
  */
@@ -555,7 +575,7 @@ void Document::LoadSVG(const string & filename, const Rect & bounds)
        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());
        
@@ -613,6 +633,8 @@ pair<unsigned, unsigned> Document::ParseSVGPathData(const string & d, const SVGM
                        x[0] = (relative) ? x[0] + dx : dx;
                        y[0] = (relative) ? y[0] + dy : dy;
                        
+                       x0 = x[0];
+                       y0 = y[0];
                        //Debug("mmoveto %f,%f", Float(x[0]),Float(y[0]));
                        command = (command == "m") ? "l" : "L";
                }
@@ -754,7 +776,7 @@ void Document::SetFont(const string & font_filename)
                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);
@@ -798,7 +820,8 @@ void Document::AddText(const string & text, Real scale, Real x, Real y)
                {
                        kerning = stbtt_GetCodepointKernAdvance(&m_font, text[i-1], text[i]);
                }
-               x += Real(font_scale) * Real(left_side_bearing + kerning);
+               Debug("%c: lsb %d, kern %d, adv_width %d", text[i], left_side_bearing, kerning, advance_width);
+               x += Real(font_scale) * Real(kerning);
                AddFontGlyphAtPoint(&m_font, text[i], font_scale, x, y);
                x += Real(font_scale) * Real(advance_width);
        }
@@ -858,6 +881,7 @@ void Document::AddFontGlyphAtPoint(stbtt_fontinfo *font, int character, Real sca
        {
                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);
 }

UCC git Repository :: git.ucc.asn.au