X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=blobdiff_plain;f=src%2Fdocument.cpp;h=6038b198501798ed66243bb8794ba9b92cad63a4;hp=9d9011efd12644a52d75af94cd00cfc09813e82e;hb=22430ba7a7e9981661efcd1e80d34ba7bb9e71a5;hpb=33d1adb60806e13863aa3b6c5e1dee9836cd3d04 diff --git a/src/document.cpp b/src/document.cpp index 9d9011e..6038b19 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -107,8 +107,9 @@ QuadTreeIndex Document::GenQuadChild(QuadTreeIndex parent, QuadTreeNodeChildren m_quadtree.nodes[new_index].object_begin = m_objects.bounds.size(); for (unsigned i = m_quadtree.nodes[parent].object_begin; i < m_quadtree.nodes[parent].object_end; ++i) { - if (ContainedInQuadChild(m_objects.bounds[i], type)) + if (IntersectsQuadChild(m_objects.bounds[i], type)) { + Debug("Adding %s -> %s", m_objects.bounds[i].Str().c_str(), TransformToQuadChild(m_objects.bounds[i], type).Str().c_str()); m_objects.bounds.push_back(TransformToQuadChild(m_objects.bounds[i], type)); m_objects.types.push_back(m_objects.types[i]); m_objects.data_indices.push_back(m_objects.data_indices[i]); @@ -682,18 +683,28 @@ void Document::AddText(const string & text, Real scale, Real x, Real y) 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); + Real y_advance = Real(font_scale) * Real(ascent - descent + line_gap); for (unsigned i = 0; i < text.size(); ++i) { if (text[i] == '\n') { - y += 0.5*scale; + y += y_advance; x = x0; } if (!isprint(text[i])) continue; + int advance_width = 0, left_side_bearing = 0, kerning = 0; + stbtt_GetCodepointHMetrics(&m_font, text[i], &advance_width, &left_side_bearing); + if (i > 1) + { + kerning = stbtt_GetCodepointKernAdvance(&m_font, text[i-1], text[i]); + } + x += Real(font_scale) * Real(left_side_bearing + kerning); AddFontGlyphAtPoint(&m_font, text[i], font_scale, x, y); - x += 0.5*scale; + x += Real(font_scale) * Real(advance_width); } }