diff options
author | Khaled Hosny <khaled@aliftype.com> | 2022-11-20 17:45:51 +0200 |
---|---|---|
committer | خالد حسني <khaled@aliftype.com> | 2022-11-20 22:17:22 +0100 |
commit | d4005521e4fe4379381605b63af1950c5aecd798 (patch) | |
tree | 771daec8bd28ca4b0a23133822643dc15edfc431 | |
parent | f88e7632b745a9b18af36cd901399c40e8b7378f (diff) |
vcl: add NeedsArtificialBold/Italic() to LogicalFontInstance
Change-Id: Ie8bab5d7653a22d0f56b4c859fb2260d96e655c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142998
Tested-by: Jenkins
Reviewed-by: خالد حسني <khaled@aliftype.com>
-rw-r--r-- | vcl/inc/font/LogicalFontInstance.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 2 | ||||
-rw-r--r-- | vcl/inc/unx/glyphcache.hxx | 4 | ||||
-rw-r--r-- | vcl/quartz/ctfonts.cxx | 17 | ||||
-rw-r--r-- | vcl/quartz/salgdi.cxx | 2 | ||||
-rw-r--r-- | vcl/skia/osx/gdiimpl.cxx | 2 | ||||
-rw-r--r-- | vcl/skia/x11/textrender.cxx | 4 | ||||
-rw-r--r-- | vcl/source/font/LogicalFontInstance.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/impglyphitem.cxx | 4 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/cairotextrender.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/glyphs/freetype_glyphcache.cxx | 15 | ||||
-rw-r--r-- | vcl/unx/generic/print/genpspgraphics.cxx | 20 |
13 files changed, 32 insertions, 66 deletions
diff --git a/vcl/inc/font/LogicalFontInstance.hxx b/vcl/inc/font/LogicalFontInstance.hxx index 8887a5d77a1d..0b40a9c7d4f7 100644 --- a/vcl/inc/font/LogicalFontInstance.hxx +++ b/vcl/inc/font/LogicalFontInstance.hxx @@ -112,6 +112,9 @@ public: // TODO: make data members private void GetScale(double* nXScale, double* nYScale) const; + bool NeedsArtificialItalic() const; + bool NeedsArtificialBold() const; + protected: explicit LogicalFontInstance(const vcl::font::PhysicalFontFace&, const vcl::font::FontSelectPattern&); diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index 4812404bbc6e..8a0fc4cfd3f0 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -94,8 +94,6 @@ public: float mfFontStretch; /// text rotation in radian float mfFontRotation; - /// faux bold - true, if font doesn't have proper bold variants - bool mbFauxBold; private: explicit CoreTextFont(const CoreTextFontFace&, const vcl::font::FontSelectPattern&); diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx index 22e2f0e173d9..9de7bd59fe6c 100644 --- a/vcl/inc/unx/glyphcache.hxx +++ b/vcl/inc/unx/glyphcache.hxx @@ -120,8 +120,6 @@ public: bool TestFont() const { return mbFaceOk;} FT_Face GetFtFace() const; const FontConfigFontOptions* GetFontOptions() const; - bool NeedsArtificialBold() const { return mbArtBold; } - bool NeedsArtificialItalic() const { return mbArtItalic; } void GetFontMetric(ImplFontMetricDataRef const &) const; @@ -154,8 +152,6 @@ private: mutable std::unique_ptr<FontConfigFontOptions> mxFontOptions; bool mbFaceOk; - bool mbArtItalic; - bool mbArtBold; }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/quartz/ctfonts.cxx b/vcl/quartz/ctfonts.cxx index 1f7be532db31..89460c3943a1 100644 --- a/vcl/quartz/ctfonts.cxx +++ b/vcl/quartz/ctfonts.cxx @@ -45,7 +45,6 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, const vcl::font::FontSe : LogicalFontInstance(rPFF, rFSP) , mfFontStretch( 1.0 ) , mfFontRotation( 0.0 ) - , mbFauxBold(false) , mpCTFont(nullptr) { double fScaledFontHeight = rFSP.mfExactHeight; @@ -63,21 +62,9 @@ CoreTextFont::CoreTextFont(const CoreTextFontFace& rPFF, const vcl::font::FontSe aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMakeScale(mfFontStretch, 1.0F)); } - // fake bold - if ( (rFSP.GetWeight() >= WEIGHT_BOLD) && - ((rPFF.GetWeight() < WEIGHT_SEMIBOLD) && - (rPFF.GetWeight() != WEIGHT_DONTKNOW)) ) - { - mbFauxBold = true; - } - - // fake italic - if (((rFSP.GetItalic() == ITALIC_NORMAL) || - (rFSP.GetItalic() == ITALIC_OBLIQUE)) && - (rPFF.GetItalic() == ITALIC_NONE)) - { + // artificial italic + if (NeedsArtificialItalic()) aMatrix = CGAffineTransformConcat(aMatrix, CGAffineTransformMake(1, 0, ARTIFICIAL_ITALIC_SKEW, 1, 0, 0)); - } CTFontDescriptorRef pFontDesc = rPFF.GetFontDescriptorRef(); mpCTFont = CTFontCreateWithFontDescriptor( pFontDesc, fScaledFontHeight, &aMatrix ); diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx index a9f879dfea90..661a7e76735e 100644 --- a/vcl/quartz/salgdi.cxx +++ b/vcl/quartz/salgdi.cxx @@ -391,7 +391,7 @@ void AquaGraphicsBackend::drawTextLayout(const GenericSalLayout& rLayout, bool b CGContextSetShouldAntialias(mrShared.maContextHolder.get(), !mrShared.mbNonAntialiasedText); CGContextSetFillColor(mrShared.maContextHolder.get(), textColor.AsArray()); - if (rFont.mbFauxBold) + if (rFont.NeedsArtificialBold()) { float fSize = rFontSelect.mnHeight / 23.0f; diff --git a/vcl/skia/osx/gdiimpl.cxx b/vcl/skia/osx/gdiimpl.cxx index e87adba1a460..6d65eedd0ec4 100644 --- a/vcl/skia/osx/gdiimpl.cxx +++ b/vcl/skia/osx/gdiimpl.cxx @@ -305,7 +305,7 @@ void AquaSkiaSalGraphicsImpl::drawTextLayout(const GenericSalLayout& rLayout, SkFont font(typeface); font.setSize(nHeight); // font.setScaleX(rFont.mfFontStretch); TODO - if (rFont.mbFauxBold) + if (rFont.NeedsArtificialBold()) font.setEmbolden(true); SkFont::Edging ePreferredAliasing diff --git a/vcl/skia/x11/textrender.cxx b/vcl/skia/x11/textrender.cxx index c97e2b6cf3cb..fed5daa8a117 100644 --- a/vcl/skia/x11/textrender.cxx +++ b/vcl/skia/x11/textrender.cxx @@ -50,9 +50,9 @@ void SkiaTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGr SkFont font(typeface); font.setSize(nHeight); font.setScaleX(1.0 * nWidth / nHeight); - if (rFont.NeedsArtificialItalic()) + if (rInstance.NeedsArtificialItalic()) font.setSkewX(-1.0 * ARTIFICIAL_ITALIC_SKEW); - if (rFont.NeedsArtificialBold()) + if (rInstance.NeedsArtificialBold()) font.setEmbolden(true); bool bSubpixelPositioning = rLayout.GetTextRenderModeForResolutionIndependentLayout(); diff --git a/vcl/source/font/LogicalFontInstance.cxx b/vcl/source/font/LogicalFontInstance.cxx index cf2fd332802e..d07a8eb9c974 100644 --- a/vcl/source/font/LogicalFontInstance.cxx +++ b/vcl/source/font/LogicalFontInstance.cxx @@ -214,4 +214,14 @@ bool LogicalFontInstance::NeedOffsetCorrection(sal_Int32 nYOffset) return bRet; } +bool LogicalFontInstance::NeedsArtificialBold() const +{ + return m_aFontSelData.GetWeight() > WEIGHT_MEDIUM && m_pFontFace->GetWeight() <= WEIGHT_MEDIUM; +} + +bool LogicalFontInstance::NeedsArtificialItalic() const +{ + return m_aFontSelData.GetItalic() != ITALIC_NONE && m_pFontFace->GetItalic() == ITALIC_NONE; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/gdi/impglyphitem.cxx b/vcl/source/gdi/impglyphitem.cxx index 34e1f5a4d187..b3422ae1a29f 100644 --- a/vcl/source/gdi/impglyphitem.cxx +++ b/vcl/source/gdi/impglyphitem.cxx @@ -496,8 +496,8 @@ SalLayoutGlyphsCache::CachedGlyphsKey::CachedGlyphsKey( const vcl::font::FontSelectPattern& rFSD = fi->GetFontSelectPattern(); disabledLigatures = rFSD.GetPitch() == PITCH_FIXED; - artificialItalic = rFSD.GetItalic() != ITALIC_NONE && fontMetric.GetItalic() == ITALIC_NONE; - artificialBold = rFSD.GetWeight() > WEIGHT_MEDIUM && fontMetric.GetWeight() <= WEIGHT_MEDIUM; + artificialItalic = fi->NeedsArtificialItalic(); + artificialBold = fi->NeedsArtificialBold(); hashValue = 0; o3tl::hash_combine(hashValue, vcl::text::FirstCharsStringHash()(text)); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 8db18ef6a6ad..4efca33b13e8 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -6498,14 +6498,8 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool } // perform artificial italics if necessary - if( ( m_aCurrentPDFState.m_aFont.GetItalic() == ITALIC_NORMAL || - m_aCurrentPDFState.m_aFont.GetItalic() == ITALIC_OBLIQUE ) && - ( GetFontInstance()->GetFontFace()->GetItalic() != ITALIC_NORMAL && - GetFontInstance()->GetFontFace()->GetItalic() != ITALIC_OBLIQUE ) - ) - { + if (GetFontInstance()->NeedsArtificialItalic()) fSkew = ARTIFICIAL_ITALIC_SKEW; - } // if the mapmode is distorted we need to adjust for that also if( m_aCurrentPDFState.m_aMapMode.GetScaleX() != m_aCurrentPDFState.m_aMapMode.GetScaleY() ) @@ -6528,8 +6522,7 @@ void PDFWriterImpl::drawLayout( SalLayout& rLayout, const OUString& rText, bool bool bPop = false; bool bABold = false; // artificial bold necessary ? - if( GetFontInstance()->GetFontFace()->GetWeight() <= WEIGHT_MEDIUM && - GetFontInstance()->GetFontSelectPattern().GetWeight() > WEIGHT_MEDIUM ) + if (GetFontInstance()->NeedsArtificialBold()) { aLine.append("q "); bPop = true; diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx index 81d3b532c12a..0d2b2c003562 100644 --- a/vcl/unx/generic/gdi/cairotextrender.cxx +++ b/vcl/unx/generic/gdi/cairotextrender.cxx @@ -285,7 +285,7 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG CairoFontsCache::CacheId aId; aId.maFace = aFace; aId.mpOptions = rFont.GetFontOptions(); - aId.mbEmbolden = rFont.NeedsArtificialBold(); + aId.mbEmbolden = rInstance.NeedsArtificialBold(); cairo_matrix_t m; @@ -340,7 +340,7 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG cairo_set_matrix(cr, &em_square); } - if (rFont.NeedsArtificialItalic()) + if (rInstance.NeedsArtificialItalic()) { cairo_matrix_t shear; cairo_matrix_init_identity(&shear); diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx index d4a50b0f0167..3477ce1cbf42 100644 --- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx +++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx @@ -408,9 +408,7 @@ FreetypeFont::FreetypeFont(FreetypeFontInstance& rFontInstance, std::shared_ptr< mnLoadFlags( 0 ), maFaceFT( nullptr ), maSizeFT( nullptr ), - mbFaceOk( false ), - mbArtItalic( false ), - mbArtBold(false) + mbFaceOk( false ) { int nPrioEmbedded = nDefaultPrioEmbedded; @@ -467,9 +465,6 @@ FreetypeFont::FreetypeFont(FreetypeFontInstance& rFontInstance, std::shared_ptr< // TODO: query GASP table for load flags mnLoadFlags = FT_LOAD_DEFAULT | FT_LOAD_IGNORE_TRANSFORM; - mbArtItalic = (rFSD.GetItalic() != ITALIC_NONE && mxFontInfo->GetFontAttributes().GetItalic() == ITALIC_NONE); - mbArtBold = (rFSD.GetWeight() > WEIGHT_MEDIUM && mxFontInfo->GetFontAttributes().GetWeight() <= WEIGHT_MEDIUM); - if( ((mnCos != 0) && (mnSin != 0)) || (nPrioEmbedded <= 0) ) mnLoadFlags |= FT_LOAD_NO_BITMAP; } @@ -487,7 +482,7 @@ const FontConfigFontOptions* FreetypeFont::GetFontOptions() const if (!mxFontOptions) { mxFontOptions = GetFCFontOptions(mxFontInfo->GetFontAttributes(), mrFontInstance.GetFontSelectPattern().mnHeight); - mxFontOptions->SyncPattern(GetFontFileName(), GetFontFaceIndex(), GetFontFaceVariation(), NeedsArtificialBold()); + mxFontOptions->SyncPattern(GetFontFileName(), GetFontFaceIndex(), GetFontFaceVariation(), mrFontInstance.NeedsArtificialBold()); } return mxFontOptions.get(); } @@ -633,7 +628,7 @@ bool FreetypeFont::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle& rRect, b if (rc != FT_Err_Ok) return false; - if (mbArtBold) + if (mrFontInstance.NeedsArtificialBold()) FT_GlyphSlot_Embolden(maFaceFT->glyph); FT_Glyph pGlyphFT; @@ -841,7 +836,7 @@ bool FreetypeFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rB2 if( rc != FT_Err_Ok ) return false; - if (mbArtBold) + if (mrFontInstance.NeedsArtificialBold()) FT_GlyphSlot_Embolden(maFaceFT->glyph); FT_Glyph pGlyphFT; @@ -855,7 +850,7 @@ bool FreetypeFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rB2 return false; } - if( mbArtItalic ) + if (mrFontInstance.NeedsArtificialItalic()) { FT_Matrix aMatrix; aMatrix.xx = aMatrix.yy = ARTIFICIAL_ITALIC_MATRIX_XX; diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx index fe3e37627fd9..29049cb44d69 100644 --- a/vcl/unx/generic/print/genpspgraphics.cxx +++ b/vcl/unx/generic/print/genpspgraphics.cxx @@ -170,22 +170,6 @@ void GenPspGraphics::SetFont(LogicalFontInstance *pFontInstance, int nFallbackLe const vcl::font::FontSelectPattern& rEntry = pFontInstance->GetFontSelectPattern(); - // determine which font attributes need to be emulated - bool bArtItalic = false; - bool bArtBold = false; - if( rEntry.GetItalic() == ITALIC_OBLIQUE || rEntry.GetItalic() == ITALIC_NORMAL ) - { - FontItalic eItalic = m_pPrinterGfx->GetFontMgr().getFontItalic( nID ); - if( eItalic != ITALIC_NORMAL && eItalic != ITALIC_OBLIQUE ) - bArtItalic = true; - } - FontWeight nWeight = rEntry.GetWeight(); - FontWeight nRealWeight = m_pPrinterGfx->GetFontMgr().getFontWeight( nID ); - if( nRealWeight <= WEIGHT_MEDIUM && nWeight > WEIGHT_MEDIUM ) - { - bArtBold = true; - } - // also set the serverside font for layouting // requesting a font provided by builtin rasterizer FreetypeFontInstance* pFreetypeFont = static_cast<FreetypeFontInstance*>(pFontInstance); @@ -201,8 +185,8 @@ void GenPspGraphics::SetFont(LogicalFontInstance *pFontInstance, int nFallbackLe rEntry.mnWidth, rEntry.mnOrientation, rEntry.mbVertical, - bArtItalic, - bArtBold + pFontInstance->NeedsArtificialItalic(), + pFontInstance->NeedsArtificialBold() ); } |