From: David Gow Date: Tue, 19 Aug 2014 12:11:57 +0000 (+0800) Subject: Fix adding text. X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=16f404f3edf222c467639f3e898eeb505075cde8;p=ipdf%2Fcode.git Fix adding text. (And remove some Debug printing) --- diff --git a/src/controlpanel.cpp b/src/controlpanel.cpp index 41013d0..f2d0324 100644 --- a/src/controlpanel.cpp +++ b/src/controlpanel.cpp @@ -224,14 +224,13 @@ void ControlPanel::SetViewBounds() void ControlPanel::InsertTextIntoDocument() { const Rect & bounds = m_view.GetBounds(); - Real xx = bounds.x + bounds.w/Real(2); + Real xx = bounds.x; Real yy = bounds.y + bounds.h/Real(2); string msg = m_text_edit->toPlainText().toStdString(); - Real scale = bounds.w / Real(2); + Real scale = bounds.h / Real(2); Debug("Insert \"%s\" at %f, %f, scale %f", msg.c_str(), Float(xx), Float(yy), Float(scale)); - //m_doc.Add(RECT_OUTLINE, bounds, 0); // debugging; text needs to go in the boujnds - m_doc.AddText(msg, xx, yy, scale); + m_doc.AddText(msg, scale, xx, yy); m_view.ForceRenderDirty(); m_view.ForceBufferDirty(); m_view.ForceBoundsDirty(); diff --git a/src/document.cpp b/src/document.cpp index 48e15a8..c4ba210 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -798,11 +798,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) { @@ -820,7 +820,6 @@ void Document::AddText(const string & text, Real scale, Real x, Real y) { 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);