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>
This commit is contained in:
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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<
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user