Added a profiler, which outputs time taken and calls to various functions.
[ipdf/code.git] / src / document.cpp
index b347c76..aff9a23 100644 (file)
@@ -1,5 +1,6 @@
 #include "document.h"
 #include "bezier.h"
+#include "profiler.h"
 #include <cstdio>
 #include <fstream>
 
@@ -101,6 +102,7 @@ void Document::GenBaseQuadtree()
 
 int Document::ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type)
 {
+       PROFILE_SCOPE("Document::ClipObjectToQuadChild");
        switch (m_objects.types[object_id])
        {
        case RECT_FILLED:
@@ -168,6 +170,7 @@ int Document::ClipObjectToQuadChild(int object_id, QuadTreeNodeChildren type)
 }
 QuadTreeIndex Document::GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren type)
 {
+       PROFILE_SCOPE("Document::GenQuadChild()");
        QuadTreeIndex new_index = m_quadtree.nodes.size();
        Debug("-------------- Generating Quadtree Node %d (parent %d, type %d) ----------------------", new_index, parent, type);
        m_quadtree.nodes.push_back(QuadTreeNode{QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, parent, type, 0, 0, -1});
@@ -208,6 +211,7 @@ QuadTreeIndex Document::GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren
 
 void Document::OverlayQuadChildren(QuadTreeIndex orig_parent, QuadTreeIndex parent, QuadTreeNodeChildren type)
 {
+       PROFILE_SCOPE("Document::OverlayQuadChildren()");
        QuadTreeIndex new_index = m_quadtree.nodes.size();
        Debug("-------------- Generating Quadtree Node %d (orig %d parent %d, type %d) ----------------------", new_index, orig_parent, parent, type);
        m_quadtree.nodes.push_back(QuadTreeNode{QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, QUADTREE_EMPTY, orig_parent, type, 0, 0, -1});
@@ -413,6 +417,7 @@ unsigned Document::AddBezier(const Bezier & bezier)
 
 unsigned Document::Add(ObjectType type, const Rect & bounds, unsigned data_index, QuadTreeIndex qti)
 {
+       PROFILE_SCOPE("Document::Add");
        m_objects.types.push_back(type);
        m_objects.bounds.push_back(bounds);
        m_objects.data_indices.push_back(data_index);
@@ -445,8 +450,11 @@ done: // matches is not amused, but sulix is nice and moved it inside the #ifdef
                m_count++;
                PropagateQuadChanges(qti);
        }
+       return m_count-1;
+#else // words fail me (still not amused)
+       return (m_count++);
 #endif
-       return m_count; // Why can't we just use the size of types or something?
+       
 }
 
 unsigned Document::AddBezierData(const Bezier & bezier)
@@ -1142,28 +1150,43 @@ void Document::AddFontGlyphAtPoint(stbtt_fontinfo *font, int character, Real sca
        stbtt_FreeShape(font, instructions);
 }
 
-void Document::TransformObjectBounds(const SVGMatrix & transform)
+void Document::TransformObjectBounds(const SVGMatrix & transform, ObjectType type)
 {
+       #ifdef TRANSFORM_BEZIERS_TO_PATH
+               for (unsigned i = 0; i < m_objects.paths.size(); ++i)
+               {
+                       Path & p = m_objects.paths[i];
+                       p.m_bounds.x = transform.a * p.m_bounds.x + transform.e;
+                       p.m_bounds.y = transform.d * p.m_bounds.y + transform.f;
+                       p.m_bounds.w *= transform.a;
+                       p.m_bounds.h *= transform.d;
+               }
+               return;
+       #endif          
+       
        for (unsigned i = 0; i < m_count; ++i)
        {
-               TransformXYPair(m_objects.bounds[i].x, m_objects.bounds[i].y, transform);
-               m_objects.bounds[i].w *= transform.a;
-               m_objects.bounds[i].h *= transform.d;
+               if (type == NUMBER_OF_OBJECT_TYPES || m_objects.types[i] == type)
+               {
+                       TransformXYPair(m_objects.bounds[i].x, m_objects.bounds[i].y, transform);
+                       m_objects.bounds[i].w *= transform.a;
+                       m_objects.bounds[i].h *= transform.d;
+               }
        }
 }
 
 void Document::TranslateObjects(const Real & dx, const Real & dy, ObjectType type)
 {
        #ifdef TRANSFORM_BEZIERS_TO_PATH
-               for (unsigned i = 0; i < m_objects.paths.size(); ++i)
-               {
-                       Path & p = m_objects.paths[i];
-                       p.m_bounds.x += dx;
-                       p.m_bounds.y += dy;
-               }
-               return;
-       #endif  
-       
+       for (unsigned i = 0; i < m_objects.paths.size(); ++i)
+       {
+               Path & p = m_objects.paths[i];
+               p.m_bounds.x += dx;
+               p.m_bounds.y += dy;
+       }
+       return;
+       #endif
+
        for (unsigned i = 0; i < m_count; ++i)
        {
                if (type == NUMBER_OF_OBJECT_TYPES || m_objects.types[i] == type)

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