diff options
author | Vort <vvort@yandex.ru> | 2014-05-20 09:05:33 +0300 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-05-20 06:55:32 -0500 |
commit | be7ec1384e85360179f5645d9775c5e6605d5a0f (patch) | |
tree | c0618b67a50c7188c6a96e7d883838dd6155f63f /sdext | |
parent | Related: fdo#78151 disable promote or demote outline levels in master view (diff) | |
download | core-be7ec1384e85360179f5645d9775c5e6605d5a0f.tar.gz core-be7ec1384e85360179f5645d9775c5e6605d5a0f.zip |
fdo#78689 PDF Import: get font's ascent value from different source
Change-Id: I19018d25ef53bbea225bb5a9ef806ce5c1b4adc7
Reviewed-on: https://gerrit.libreoffice.org/9410
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sdext')
-rw-r--r-- | sdext/source/pdfimport/inc/contentsink.hxx | 18 | ||||
-rw-r--r-- | sdext/source/pdfimport/test/tests.cxx | 3 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/pdfiprocessor.cxx | 16 | ||||
-rw-r--r-- | sdext/source/pdfimport/tree/pdfiprocessor.hxx | 3 | ||||
-rw-r--r-- | sdext/source/pdfimport/wrapper/wrapper.cxx | 31 | ||||
-rw-r--r-- | sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx | 33 |
6 files changed, 57 insertions, 47 deletions
diff --git a/sdext/source/pdfimport/inc/contentsink.hxx b/sdext/source/pdfimport/inc/contentsink.hxx index 93ae5adb19e0..d4fb3b187e90 100644 --- a/sdext/source/pdfimport/inc/contentsink.hxx +++ b/sdext/source/pdfimport/inc/contentsink.hxx @@ -52,13 +52,15 @@ namespace pdfi bool isItalic_, bool isUnderline_, bool isOutline_, - double size_ ) : + double size_, + double ascent_) : familyName(familyName_), isBold(isBold_), isItalic(isItalic_), isUnderline(isUnderline_), isOutline(isOutline_), - size(size_) + size(size_), + ascent(ascent_) {} FontAttributes() : @@ -67,7 +69,8 @@ namespace pdfi isItalic(false), isUnderline(false), isOutline(false), - size(0.0) + size(0.0), + ascent(1.0) {} OUString familyName; @@ -76,6 +79,7 @@ namespace pdfi bool isUnderline; bool isOutline; double size; // device pixel + double ascent; bool operator==(const FontAttributes& rFont) const { @@ -84,7 +88,8 @@ namespace pdfi !isItalic == !rFont.isItalic && !isUnderline == !rFont.isUnderline && !isOutline == !rFont.isOutline && - size == rFont.size; + size == rFont.size && + ascent == rFont.ascent; } }; @@ -135,9 +140,10 @@ namespace pdfi virtual void intersectEoClip(const css::uno::Reference< css::rendering::XPolyPolygon2D >& rPath) = 0; - virtual void drawGlyphs( const OUString& rGlyphs, + virtual void drawGlyphs( const OUString& rGlyphs, const css::geometry::RealRectangle2D& rRect, - const css::geometry::Matrix2D& rFontMatrix ) = 0; + const css::geometry::Matrix2D& rFontMatrix, + double fontSize) = 0; /// issued when a sequence of associated glyphs is drawn virtual void endText() = 0; diff --git a/sdext/source/pdfimport/test/tests.cxx b/sdext/source/pdfimport/test/tests.cxx index aa11ea6f8d28..8b47c0a6470f 100644 --- a/sdext/source/pdfimport/test/tests.cxx +++ b/sdext/source/pdfimport/test/tests.cxx @@ -346,7 +346,8 @@ namespace virtual void drawGlyphs( const OUString& rGlyphs, const geometry::RealRectangle2D& /*rRect*/, - const geometry::Matrix2D& /*rFontMatrix*/ ) SAL_OVERRIDE + const geometry::Matrix2D& /*rFontMatrix*/, + double /*fontSize*/) SAL_OVERRIDE { m_aTextOut.append(rGlyphs); } diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.cxx b/sdext/source/pdfimport/tree/pdfiprocessor.cxx index 487ba20c01ed..3a670a64c38a 100644 --- a/sdext/source/pdfimport/tree/pdfiprocessor.cxx +++ b/sdext/source/pdfimport/tree/pdfiprocessor.cxx @@ -277,14 +277,20 @@ void PDFIProcessor::processGlyphLine() void PDFIProcessor::drawGlyphs( const OUString& rGlyphs, const geometry::RealRectangle2D& rRect, - const geometry::Matrix2D& rFontMatrix ) + const geometry::Matrix2D& rFontMatrix, + double fontSize) { + double ascent = getFont(getCurrentContext().FontId).ascent; + + double ascentdx = rFontMatrix.m01 * ascent * fontSize; + double ascentdy = rFontMatrix.m11 * ascent * fontSize; + basegfx::B2DHomMatrix totalTextMatrix1( - rFontMatrix.m00, rFontMatrix.m01, rRect.X1, - rFontMatrix.m10, rFontMatrix.m11, rRect.Y1); + rFontMatrix.m00, rFontMatrix.m01, rRect.X1 + ascentdx, + rFontMatrix.m10, rFontMatrix.m11, rRect.Y1 + ascentdy); basegfx::B2DHomMatrix totalTextMatrix2( - rFontMatrix.m00, rFontMatrix.m01, rRect.X2, - rFontMatrix.m10, rFontMatrix.m11, rRect.Y2); + rFontMatrix.m00, rFontMatrix.m01, rRect.X2 + ascentdx, + rFontMatrix.m10, rFontMatrix.m11, rRect.Y2 + ascentdy); totalTextMatrix1 *= getCurrentContext().Transformation; totalTextMatrix2 *= getCurrentContext().Transformation; diff --git a/sdext/source/pdfimport/tree/pdfiprocessor.hxx b/sdext/source/pdfimport/tree/pdfiprocessor.hxx index 6125d1946bb7..26f73f4bee7c 100644 --- a/sdext/source/pdfimport/tree/pdfiprocessor.hxx +++ b/sdext/source/pdfimport/tree/pdfiprocessor.hxx @@ -140,7 +140,8 @@ namespace pdfi virtual void drawGlyphs( const OUString& rGlyphs, const css::geometry::RealRectangle2D& rRect, - const css::geometry::Matrix2D& rFontMatrix ) SAL_OVERRIDE; + const css::geometry::Matrix2D& rFontMatrix, + double fontSize) SAL_OVERRIDE; virtual void endText() SAL_OVERRIDE; virtual void drawMask(const css::uno::Sequence< diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index 6d8567e6196d..08519a5309b5 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -56,6 +56,10 @@ #include "basegfx/tools/canvastools.hxx" #include "basegfx/tools/unopolypolygon.hxx" +#include <vcl/metric.hxx> +#include <vcl/font.hxx> +#include <vcl/virdev.hxx> + #include <boost/scoped_ptr.hpp> #include <boost/unordered_map.hpp> #include <string.h> @@ -356,6 +360,7 @@ uno::Reference<rendering::XPolyPolygon2D> Parser::readPath() void Parser::readChar() { + double fontSize; geometry::Matrix2D aUnoMatrix; geometry::RealRectangle2D aRect; @@ -367,15 +372,15 @@ void Parser::readChar() readDouble(aUnoMatrix.m01); readDouble(aUnoMatrix.m10); readDouble(aUnoMatrix.m11); + readDouble(fontSize); OString aChars = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) ); // chars gobble up rest of line m_nCharIndex = -1; - m_pSink->drawGlyphs( OStringToOUString( aChars, - RTL_TEXTENCODING_UTF8 ), - aRect, aUnoMatrix ); + m_pSink->drawGlyphs(OStringToOUString(aChars, RTL_TEXTENCODING_UTF8), + aRect, aUnoMatrix, fontSize); } void Parser::readLineCap() @@ -598,7 +603,8 @@ void Parser::readFont() nIsItalic != 0, nIsUnderline != 0, false, - nSize ); + nSize, + 1.0); // extract textual attributes (bold, italic in the name, etc.) parseFontFamilyName(aResult); @@ -625,8 +631,11 @@ void Parser::readFont() uno::Any aRes( xMat->getMaterial() ); if( aRes >>= aFD ) { - aResult.familyName = aFD.Name; - parseFontFamilyName(aResult); + if (!aFD.Name.isEmpty()) + { + aResult.familyName = aFD.Name; + parseFontFamilyName(aResult); + } aResult.isBold = (aFD.Weight > 100.0); aResult.isItalic = (aFD.Slant == awt::FontSlant_OBLIQUE || aFD.Slant == awt::FontSlant_ITALIC ); @@ -647,6 +656,16 @@ void Parser::readFont() } } + + static VirtualDevice* vDev = 0; + if (vDev == 0) + vDev = new VirtualDevice; + + Font font(aResult.familyName, Size(0, 1000)); + vDev->SetFont(font); + FontMetric metric(vDev->GetFontMetric()); + aResult.ascent = metric.GetAscent() / 1000.0; + m_aFontMap[nFontID] = aResult; aResult.size = nSize; diff --git a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx index c5096ad44912..e3a779eab957 100644 --- a/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/pdfioutdev_gpl.cxx @@ -847,38 +847,13 @@ void PDFOutDev::drawChar(GfxState *state, double x, double y, if( u == NULL ) return; - GfxFont* font = state->getFont(); - double ascent = font->getAscent(); - GooString* fontName = font->getName(); - - // Hackfix until incorrect ascent values are fixed in poppler (fdo#75667) - if ((fontName->cmpN("Arial", 5) == 0) && - (ascent > 0.717) && (ascent < 0.719)) - { - ascent = 0.905; - } - else if ((fontName->cmpN("Times New Roman", 15) == 0) && - (ascent > 0.682) && (ascent < 0.684)) - { - ascent = 0.891; - } - - // normalize coordinates: correct from baseline-relative to upper - // left corner of glyphs - double x2(0.0), y2(0.0); - state->textTransformDelta( 0.0, - ascent, - &x2, &y2 ); - - const double fFontSize(state->getFontSize()); - x += x2*fFontSize; - y += y2*fFontSize; + const double fontSize = state->getFontSize(); const double aPositionX(x-originX); const double aPositionY(y-originY); const double* pTextMat=state->getTextMat(); - printf( "drawChar %f %f %f %f %f %f %f %f ", + printf( "drawChar %f %f %f %f %f %f %f %f %f ", normalize(aPositionX), normalize(aPositionY), normalize(aPositionX + dx), @@ -886,7 +861,9 @@ void PDFOutDev::drawChar(GfxState *state, double x, double y, normalize(pTextMat[0]), normalize(pTextMat[2]), normalize(pTextMat[1]), - normalize(pTextMat[3]) ); + normalize(pTextMat[3]), + normalize(fontSize) + ); // silence spurious warning (void)&mapUCS2; |