X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fdocument.cpp;h=ead1b8e6bda4427a7f6171469df1da7833e1e51c;hp=e0dd70bbff6e707b0c822094db1150c97449d10f;hb=813591a7d8a7364003233939f52b0031f3a40d20;hpb=d9c0c3792133f87cd224dc22be428be8ddc016d8 diff --git a/src/document.cpp b/src/document.cpp index e0dd70b..ead1b8e 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -130,8 +130,27 @@ 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; + case BEZIER: + { + Rect child_node_bounds = TransformFromQuadChild({0,0,1,1}, type); + Rect clip_bezier_bounds; + clip_bezier_bounds.x = (child_node_bounds.x - m_objects.bounds[object_id].x) / m_objects.bounds[object_id].w; + clip_bezier_bounds.y = (child_node_bounds.y - m_objects.bounds[object_id].y) / m_objects.bounds[object_id].h; + clip_bezier_bounds.w = child_node_bounds.w / m_objects.bounds[object_id].w; + clip_bezier_bounds.h = child_node_bounds.h / m_objects.bounds[object_id].h; + std::vector new_curves = m_objects.beziers[m_objects.data_indices[object_id]].ClipToRectangle(clip_bezier_bounds); + for (size_t i = 0; i < new_curves.size(); ++i) + { + Rect new_bounds = TransformToQuadChild(m_objects.bounds[object_id], type); + //new_bounds = TransformToQuadChild(new_bounds, type); + //Bezier new_curve_data = new_curves[i].ToRelative(new_bounds); + unsigned index = AddBezierData(new_curves[i]); + m_objects.bounds.push_back(new_bounds); + m_objects.types.push_back(BEZIER); + m_objects.data_indices.push_back(index); + } + return new_curves.size(); + } 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)); @@ -798,11 +817,11 @@ void Document::AddText(const string & text, Real scale, Real x, Real y) 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) { @@ -816,11 +835,10 @@ void Document::AddText(const string & text, Real scale, Real x, Real y) 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]); } - 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);