Fix adding text.
authorDavid Gow <[email protected]>
Tue, 19 Aug 2014 12:11:57 +0000 (20:11 +0800)
committerDavid Gow <[email protected]>
Tue, 19 Aug 2014 12:11:57 +0000 (20:11 +0800)
(And remove some Debug printing)

src/controlpanel.cpp
src/document.cpp

index 41013d0..f2d0324 100644 (file)
@@ -224,14 +224,13 @@ void ControlPanel::SetViewBounds()
 void ControlPanel::InsertTextIntoDocument()
 {
        const Rect & bounds = m_view.GetBounds();
 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 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));
        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();
        m_view.ForceRenderDirty();
        m_view.ForceBufferDirty();
        m_view.ForceBoundsDirty();
index 48e15a8..c4ba210 100644 (file)
@@ -798,11 +798,11 @@ void Document::AddText(const string & text, Real scale, Real x, Real y)
                return;
        }
                
                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);
        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)
        {
        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]);
                }
                {
                        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);
                x += Real(font_scale) * Real(kerning);
                AddFontGlyphAtPoint(&m_font, text[i], font_scale, x, y);
                x += Real(font_scale) * Real(advance_width);

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