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 isItalic_,
|
||||||
bool isUnderline_,
|
bool isUnderline_,
|
||||||
bool isOutline_,
|
bool isOutline_,
|
||||||
double size_ ) :
|
double size_,
|
||||||
|
double ascent_) :
|
||||||
familyName(familyName_),
|
familyName(familyName_),
|
||||||
isBold(isBold_),
|
isBold(isBold_),
|
||||||
isItalic(isItalic_),
|
isItalic(isItalic_),
|
||||||
isUnderline(isUnderline_),
|
isUnderline(isUnderline_),
|
||||||
isOutline(isOutline_),
|
isOutline(isOutline_),
|
||||||
size(size_)
|
size(size_),
|
||||||
|
ascent(ascent_)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
FontAttributes() :
|
FontAttributes() :
|
||||||
@@ -67,7 +69,8 @@ namespace pdfi
|
|||||||
isItalic(false),
|
isItalic(false),
|
||||||
isUnderline(false),
|
isUnderline(false),
|
||||||
isOutline(false),
|
isOutline(false),
|
||||||
size(0.0)
|
size(0.0),
|
||||||
|
ascent(1.0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
OUString familyName;
|
OUString familyName;
|
||||||
@@ -76,6 +79,7 @@ namespace pdfi
|
|||||||
bool isUnderline;
|
bool isUnderline;
|
||||||
bool isOutline;
|
bool isOutline;
|
||||||
double size; // device pixel
|
double size; // device pixel
|
||||||
|
double ascent;
|
||||||
|
|
||||||
bool operator==(const FontAttributes& rFont) const
|
bool operator==(const FontAttributes& rFont) const
|
||||||
{
|
{
|
||||||
@@ -84,7 +88,8 @@ namespace pdfi
|
|||||||
!isItalic == !rFont.isItalic &&
|
!isItalic == !rFont.isItalic &&
|
||||||
!isUnderline == !rFont.isUnderline &&
|
!isUnderline == !rFont.isUnderline &&
|
||||||
!isOutline == !rFont.isOutline &&
|
!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<
|
virtual void intersectEoClip(const css::uno::Reference<
|
||||||
css::rendering::XPolyPolygon2D >& rPath) = 0;
|
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::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
|
/// issued when a sequence of associated glyphs is drawn
|
||||||
virtual void endText() = 0;
|
virtual void endText() = 0;
|
||||||
|
@@ -346,7 +346,8 @@ namespace
|
|||||||
|
|
||||||
virtual void drawGlyphs( const OUString& rGlyphs,
|
virtual void drawGlyphs( const OUString& rGlyphs,
|
||||||
const geometry::RealRectangle2D& /*rRect*/,
|
const geometry::RealRectangle2D& /*rRect*/,
|
||||||
const geometry::Matrix2D& /*rFontMatrix*/ ) SAL_OVERRIDE
|
const geometry::Matrix2D& /*rFontMatrix*/,
|
||||||
|
double /*fontSize*/) SAL_OVERRIDE
|
||||||
{
|
{
|
||||||
m_aTextOut.append(rGlyphs);
|
m_aTextOut.append(rGlyphs);
|
||||||
}
|
}
|
||||||
|
@@ -277,14 +277,20 @@ void PDFIProcessor::processGlyphLine()
|
|||||||
|
|
||||||
void PDFIProcessor::drawGlyphs( const OUString& rGlyphs,
|
void PDFIProcessor::drawGlyphs( const OUString& rGlyphs,
|
||||||
const geometry::RealRectangle2D& rRect,
|
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(
|
basegfx::B2DHomMatrix totalTextMatrix1(
|
||||||
rFontMatrix.m00, rFontMatrix.m01, rRect.X1,
|
rFontMatrix.m00, rFontMatrix.m01, rRect.X1 + ascentdx,
|
||||||
rFontMatrix.m10, rFontMatrix.m11, rRect.Y1);
|
rFontMatrix.m10, rFontMatrix.m11, rRect.Y1 + ascentdy);
|
||||||
basegfx::B2DHomMatrix totalTextMatrix2(
|
basegfx::B2DHomMatrix totalTextMatrix2(
|
||||||
rFontMatrix.m00, rFontMatrix.m01, rRect.X2,
|
rFontMatrix.m00, rFontMatrix.m01, rRect.X2 + ascentdx,
|
||||||
rFontMatrix.m10, rFontMatrix.m11, rRect.Y2);
|
rFontMatrix.m10, rFontMatrix.m11, rRect.Y2 + ascentdy);
|
||||||
totalTextMatrix1 *= getCurrentContext().Transformation;
|
totalTextMatrix1 *= getCurrentContext().Transformation;
|
||||||
totalTextMatrix2 *= getCurrentContext().Transformation;
|
totalTextMatrix2 *= getCurrentContext().Transformation;
|
||||||
|
|
||||||
|
@@ -140,7 +140,8 @@ namespace pdfi
|
|||||||
|
|
||||||
virtual void drawGlyphs( const OUString& rGlyphs,
|
virtual void drawGlyphs( const OUString& rGlyphs,
|
||||||
const css::geometry::RealRectangle2D& rRect,
|
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 endText() SAL_OVERRIDE;
|
||||||
|
|
||||||
virtual void drawMask(const css::uno::Sequence<
|
virtual void drawMask(const css::uno::Sequence<
|
||||||
|
@@ -56,6 +56,10 @@
|
|||||||
#include "basegfx/tools/canvastools.hxx"
|
#include "basegfx/tools/canvastools.hxx"
|
||||||
#include "basegfx/tools/unopolypolygon.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/scoped_ptr.hpp>
|
||||||
#include <boost/unordered_map.hpp>
|
#include <boost/unordered_map.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -356,6 +360,7 @@ uno::Reference<rendering::XPolyPolygon2D> Parser::readPath()
|
|||||||
|
|
||||||
void Parser::readChar()
|
void Parser::readChar()
|
||||||
{
|
{
|
||||||
|
double fontSize;
|
||||||
geometry::Matrix2D aUnoMatrix;
|
geometry::Matrix2D aUnoMatrix;
|
||||||
geometry::RealRectangle2D aRect;
|
geometry::RealRectangle2D aRect;
|
||||||
|
|
||||||
@@ -367,15 +372,15 @@ void Parser::readChar()
|
|||||||
readDouble(aUnoMatrix.m01);
|
readDouble(aUnoMatrix.m01);
|
||||||
readDouble(aUnoMatrix.m10);
|
readDouble(aUnoMatrix.m10);
|
||||||
readDouble(aUnoMatrix.m11);
|
readDouble(aUnoMatrix.m11);
|
||||||
|
readDouble(fontSize);
|
||||||
|
|
||||||
OString aChars = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
|
OString aChars = lcl_unescapeLineFeeds( m_aLine.copy( m_nCharIndex ) );
|
||||||
|
|
||||||
// chars gobble up rest of line
|
// chars gobble up rest of line
|
||||||
m_nCharIndex = -1;
|
m_nCharIndex = -1;
|
||||||
|
|
||||||
m_pSink->drawGlyphs( OStringToOUString( aChars,
|
m_pSink->drawGlyphs(OStringToOUString(aChars, RTL_TEXTENCODING_UTF8),
|
||||||
RTL_TEXTENCODING_UTF8 ),
|
aRect, aUnoMatrix, fontSize);
|
||||||
aRect, aUnoMatrix );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Parser::readLineCap()
|
void Parser::readLineCap()
|
||||||
@@ -598,7 +603,8 @@ void Parser::readFont()
|
|||||||
nIsItalic != 0,
|
nIsItalic != 0,
|
||||||
nIsUnderline != 0,
|
nIsUnderline != 0,
|
||||||
false,
|
false,
|
||||||
nSize );
|
nSize,
|
||||||
|
1.0);
|
||||||
|
|
||||||
// extract textual attributes (bold, italic in the name, etc.)
|
// extract textual attributes (bold, italic in the name, etc.)
|
||||||
parseFontFamilyName(aResult);
|
parseFontFamilyName(aResult);
|
||||||
@@ -625,8 +631,11 @@ void Parser::readFont()
|
|||||||
uno::Any aRes( xMat->getMaterial() );
|
uno::Any aRes( xMat->getMaterial() );
|
||||||
if( aRes >>= aFD )
|
if( aRes >>= aFD )
|
||||||
{
|
{
|
||||||
aResult.familyName = aFD.Name;
|
if (!aFD.Name.isEmpty())
|
||||||
parseFontFamilyName(aResult);
|
{
|
||||||
|
aResult.familyName = aFD.Name;
|
||||||
|
parseFontFamilyName(aResult);
|
||||||
|
}
|
||||||
aResult.isBold = (aFD.Weight > 100.0);
|
aResult.isBold = (aFD.Weight > 100.0);
|
||||||
aResult.isItalic = (aFD.Slant == awt::FontSlant_OBLIQUE ||
|
aResult.isItalic = (aFD.Slant == awt::FontSlant_OBLIQUE ||
|
||||||
aFD.Slant == awt::FontSlant_ITALIC );
|
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;
|
m_aFontMap[nFontID] = aResult;
|
||||||
|
|
||||||
aResult.size = nSize;
|
aResult.size = nSize;
|
||||||
|
@@ -847,38 +847,13 @@ void PDFOutDev::drawChar(GfxState *state, double x, double y,
|
|||||||
if( u == NULL )
|
if( u == NULL )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GfxFont* font = state->getFont();
|
const double fontSize = state->getFontSize();
|
||||||
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 aPositionX(x-originX);
|
const double aPositionX(x-originX);
|
||||||
const double aPositionY(y-originY);
|
const double aPositionY(y-originY);
|
||||||
|
|
||||||
const double* pTextMat=state->getTextMat();
|
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(aPositionX),
|
||||||
normalize(aPositionY),
|
normalize(aPositionY),
|
||||||
normalize(aPositionX + dx),
|
normalize(aPositionX + dx),
|
||||||
@@ -886,7 +861,9 @@ void PDFOutDev::drawChar(GfxState *state, double x, double y,
|
|||||||
normalize(pTextMat[0]),
|
normalize(pTextMat[0]),
|
||||||
normalize(pTextMat[2]),
|
normalize(pTextMat[2]),
|
||||||
normalize(pTextMat[1]),
|
normalize(pTextMat[1]),
|
||||||
normalize(pTextMat[3]) );
|
normalize(pTextMat[3]),
|
||||||
|
normalize(fontSize)
|
||||||
|
);
|
||||||
|
|
||||||
// silence spurious warning
|
// silence spurious warning
|
||||||
(void)&mapUCS2;
|
(void)&mapUCS2;
|
||||||
|
Reference in New Issue
Block a user