| 2032 | } |
| 2033 | |
| 2034 | void drawTextSpan( const svg::TextSpan &span ) { |
| 2035 | if( ! shouldRender( span ) ) |
| 2036 | return; |
| 2037 | |
| 2038 | #if 0 |
| 2039 | /*std::vector<std::pair<uint16_t,vec2> > glyphs = span.getGlyphMeasures(); |
| 2040 | |
| 2041 | vec2 curPoint = mCtx.getCurrentPoint(); |
| 2042 | for( size_t g = 0; g < glyphs.size(); ++g ) { |
| 2043 | mCtx.save(); |
| 2044 | mCtx.translate( glyphs[g].second.x + curPoint.x, curPoint.y ); |
| 2045 | mCtx.appendPath( font->getGlyphShape( glyphs[g].first ) ); |
| 2046 | mCtx.restore(); |
| 2047 | }*/ |
| 2048 | mCtx.appendPath( span.getShape() ); |
| 2049 | #else |
| 2050 | std::shared_ptr<Font> font = span.getFont(); |
| 2051 | mCtx.setFont( *font ); |
| 2052 | |
| 2053 | mCtx.moveTo( mTextPenStack.back() ); |
| 2054 | // we can use a text path when the rotate is empty |
| 2055 | if( fabs(mTextRotationStack.back()) < 0.0001f ) { |
| 2056 | mCtx.textPath( span.getString() ); |
| 2057 | mTextPenStack.back() = mCtx.getCurrentPoint(); |
| 2058 | } |
| 2059 | else { |
| 2060 | mCtx.save(); |
| 2061 | cairo::Matrix fontMatrix, oldFontMatrix, rotationMatrix; |
| 2062 | mCtx.getFontMatrix( &oldFontMatrix ); |
| 2063 | rotationMatrix.initRotate( toRadians( mTextRotationStack.back() ) ); |
| 2064 | fontMatrix = oldFontMatrix; |
| 2065 | fontMatrix *= rotationMatrix; |
| 2066 | mCtx.setFontMatrix( fontMatrix ); |
| 2067 | TextBox tbox = TextBox().font( *font ).text( span.getString() ); |
| 2068 | auto glyphs = tbox.measureGlyphs(); |
| 2069 | vec2 curPoint = mCtx.getCurrentPoint(); |
| 2070 | for( size_t g = 0; g < glyphs.size(); ++g ) { |
| 2071 | mCtx.save(); |
| 2072 | mCtx.translate( glyphs[g].second.x + curPoint.x, /*glyphs[g].second.y + */curPoint.y ); |
| 2073 | glyphs[g].second.x = 0; |
| 2074 | glyphs[g].second.y = 0; |
| 2075 | mCtx.glyphPath( glyphs[g].first, vec2( 0 ) ); |
| 2076 | mCtx.restore(); |
| 2077 | } |
| 2078 | mTextPenStack.back() = mCtx.getCurrentPoint(); |
| 2079 | mCtx.restore(); |
| 2080 | } |
| 2081 | #endif |
| 2082 | strokeAndFill( span ); |
| 2083 | } |
| 2084 | |
| 2085 | void pushMatrix( const mat3 &top ) { |
| 2086 | mat3 m = mMatrixStack.back() * top; |
no test coverage detected