From: Sam Moore Date: Mon, 18 Aug 2014 13:47:51 +0000 (+0800) Subject: Merge branch 'master' of git.ucc.asn.au:/ipdf/code X-Git-Url: https://git.ucc.asn.au/?p=ipdf%2Fcode.git;a=commitdiff_plain;h=398e6b2732decd57cdb57deb3f91d3ff08669e8b;hp=d9c0c3792133f87cd224dc22be428be8ddc016d8 Merge branch 'master' of git.ucc.asn.au:/ipdf/code Noooo --- diff --git a/src/bezier.h b/src/bezier.h index f3df458..9ea730f 100644 --- a/src/bezier.h +++ b/src/bezier.h @@ -16,6 +16,40 @@ namespace IPDF return std::pair(x0,x1); } + inline std::vector SolveCubic(const Real & a, const Real & b, const Real & c, const Real & d) + { + // This is going to be a big one... + // See http://en.wikipedia.org/wiki/Cubic_function#General_formula_for_roots + + // delta = 18abcd - 4 b^3 d + b^2 c^2 - 4ac^3 - 27 a^2 d^2 + /* + Real discriminant = Real(18) * a * b * c * d - Real(4) * (b * b * b) * d + + (b * b) * (c * c) - Real(4) * a * (c * c * c) + - Real(27) * (a * a) * (d * d); + */ + // discriminant > 0 => 3 distinct, real roots. + // discriminant = 0 => a multiple root (1 or 2 real roots) + // discriminant < 0 => 1 real root, 2 complex conjugate roots + + ////HACK: We know any roots we care about will be between 0 and 1, so... + Real maxi(100); + Real prevRes(d); + std::vector roots; + for(int i = 0; i <= 100; ++i) + { + Real x(i); + x /= maxi; + Real y = a*(x*x*x) + b*(x*x) + c*x + d; + if (y == Real(0) || (y < Real(0) && prevRes > Real(0)) || (y > Real(0) && prevRes < Real(0))) + { + roots.push_back(x); + } + } + return roots; + + } + + /** A _cubic_ bezier. **/ struct Bezier { diff --git a/src/document.cpp b/src/document.cpp index e0dd70b..48e15a8 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -816,7 +816,7 @@ 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]); }