[Libreoffice-commits] .: 3 commits - vcl/inc vcl/source vcl/win

Caolán McNamara caolan at kemper.freedesktop.org
Wed Mar 9 07:38:50 PST 2011


 vcl/inc/vcl/outdev.hxx         |    5 ++
 vcl/source/gdi/impvect.cxx     |    2 -
 vcl/source/gdi/outdev3.cxx     |   70 ++++++++++++++++++++++++++++++++---------
 vcl/win/inc/salgdi.h           |    1 
 vcl/win/source/gdi/salgdi3.cxx |   45 +++++++++-----------------
 5 files changed, 77 insertions(+), 46 deletions(-)

New commits:
commit c7e1506b832281f5469602bcd9ca99bab19dc716
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Mar 9 14:22:35 2011 +0000

    enable fontcapabilities under windows

diff --git a/vcl/win/inc/salgdi.h b/vcl/win/inc/salgdi.h
index e6207fd..1218ecb 100644
--- a/vcl/win/inc/salgdi.h
+++ b/vcl/win/inc/salgdi.h
@@ -119,7 +119,6 @@ private:
 private:
     void                    ReadCmapTable( HDC ) const;
     void                    GetFontCapabilities( HDC hDC ) const;
-    void                    ReadOs2Table( HDC ) const;
 
 #ifdef GNG_VERT_HACK
     void                    ReadGsubTable( HDC ) const;
diff --git a/vcl/win/source/gdi/salgdi3.cxx b/vcl/win/source/gdi/salgdi3.cxx
index 1e35e50..5760f83 100644
--- a/vcl/win/source/gdi/salgdi3.cxx
+++ b/vcl/win/source/gdi/salgdi3.cxx
@@ -1164,7 +1164,7 @@ void ImplWinFontData::UpdateFromHDC( HDC hDC ) const
         return;
 
     ReadCmapTable( hDC );
-    ReadOs2Table( hDC );
+    GetFontCapabilities( hDC );
 #ifdef ENABLE_GRAPHITE
     static const char* pDisableGraphiteText = getenv( "SAL_DISABLE_GRAPHITE" );
     if( !pDisableGraphiteText || (pDisableGraphiteText[0] == '0') )
@@ -1222,31 +1222,6 @@ static unsigned GetUShort( const unsigned char* p ){ return((p[0]<<8)+p[1]);}
 //static signed GetSShort( const unsigned char* p ){ return((short)((p[0]<<8)+p[1]));}
 static inline DWORD CalcTag( const char p[4]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
 
-void ImplWinFontData::ReadOs2Table( HDC hDC ) const
-{
-    const DWORD Os2Tag = CalcTag( "OS/2" );
-    DWORD nLength = ::GetFontData( hDC, Os2Tag, 0, NULL, 0 );
-    if( (nLength == GDI_ERROR) || !nLength )
-        return;
-    std::vector<unsigned char> aOS2map( nLength );
-    unsigned char* pOS2map = &aOS2map[0];
-    ::GetFontData( hDC, Os2Tag, 0, pOS2map, nLength );
-    sal_uInt32 nVersion = GetUShort( pOS2map );
-    if ( nVersion >= 0x0001 && nLength >= 58 )
-    {
-        // We need at least version 0x0001 (TrueType rev 1.66)
-        // to have access to the needed struct members.
-        sal_uInt32 ulUnicodeRange1 = GetUInt( pOS2map + 42 );
-        sal_uInt32 ulUnicodeRange2 = GetUInt( pOS2map + 46 );
-
-        // Check for CJK capabilities of the current font
-        mbHasCJKSupport = (ulUnicodeRange2 & 0x2DF00000);
-        mbHasKoreanRange= (ulUnicodeRange1 & 0x10000000)
-                        | (ulUnicodeRange2 & 0x01100000);
-        mbHasArabicSupport = (ulUnicodeRange1 & 0x00002000);
-   }
-}
-
 // -----------------------------------------------------------------------
 
 void ImplWinFontData::ReadGsubTable( HDC hDC ) const
@@ -1331,7 +1306,7 @@ void ImplWinFontData::GetFontCapabilities( HDC hDC ) const
     DWORD nLength;
     const DWORD GsubTag = CalcTag( "GSUB" );
     nLength = ::GetFontData( hDC, GsubTag, 0, NULL, 0 );
-    if( (nLength != GDI_ERROR) & nLength )
+    if( (nLength != GDI_ERROR) && nLength )
     {
         std::vector<unsigned char> aTable( nLength );
         unsigned char* pTable = &aTable[0];
@@ -1342,12 +1317,24 @@ void ImplWinFontData::GetFontCapabilities( HDC hDC ) const
     // OS/2 table
     const DWORD OS2Tag = CalcTag( "OS/2" );
     nLength = ::GetFontData( hDC, OS2Tag, 0, NULL, 0 );
-    if( (nLength != GDI_ERROR) & nLength )
+    if( (nLength != GDI_ERROR) && nLength )
     {
         std::vector<unsigned char> aTable( nLength );
         unsigned char* pTable = &aTable[0];
         ::GetFontData( hDC, OS2Tag, 0, pTable, nLength );
-        vcl::getTTCoverage(maFontCapabilities.maUnicodeRange, maFontCapabilities.maCodePageRange, pTable, nLength);
+        if (vcl::getTTCoverage(maFontCapabilities.maUnicodeRange, maFontCapabilities.maCodePageRange, pTable, nLength))
+        {
+            // Check for CJK capabilities of the current font
+            // TODO, we have this info already from getTT, decode bits to
+            // a readable dynamic_bitset
+            sal_uInt32 ulUnicodeRange1 = GetUInt( pTable + 42 );
+            sal_uInt32 ulUnicodeRange2 = GetUInt( pTable + 46 );
+
+            mbHasCJKSupport = (ulUnicodeRange2 & 0x2DF00000);
+            mbHasKoreanRange= (ulUnicodeRange1 & 0x10000000)
+                            | (ulUnicodeRange2 & 0x01100000);
+            mbHasArabicSupport = (ulUnicodeRange1 & 0x00002000);
+        }
     }
 }
 
commit 39387fda8c027722d7db2a1320a2bebf95efb641
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Mar 9 14:22:04 2011 +0000

    Resolves: rhbz#682621 better resizing of overtall glyphsubs

diff --git a/vcl/inc/vcl/outdev.hxx b/vcl/inc/vcl/outdev.hxx
index 251b2e8..859020f 100644
--- a/vcl/inc/vcl/outdev.hxx
+++ b/vcl/inc/vcl/outdev.hxx
@@ -276,6 +276,8 @@ enum OutDevViewType { OUTDEV_VIEWTYPE_DONTKNOW, OUTDEV_VIEWTYPE_PRINTPREVIEW, OU
 
 class VirtualDevice;
 class Printer;
+class ImplFontSelectData;
+class ImplFontMetricData;
 
 const char* ImplDbgCheckOutputDevice( const void* pObj );
 
@@ -563,6 +565,9 @@ public:
     // Helper for line geometry paint with support for graphic expansion (pattern and fat_to_area)
     void impPaintLineGeometryWithEvtlExpand(const LineInfo& rInfo, basegfx::B2DPolyPolygon aLinePolyPolygon);
 
+    SAL_DLLPRIVATE void forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &rFallbackFont,
+        ImplFontSelectData &rFontSelData, int nFallbackLevel,
+        ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const;
 protected:
                         OutputDevice();
 
diff --git a/vcl/source/gdi/outdev3.cxx b/vcl/source/gdi/outdev3.cxx
index 84a7b5d..7a439f2 100644
--- a/vcl/source/gdi/outdev3.cxx
+++ b/vcl/source/gdi/outdev3.cxx
@@ -6015,6 +6015,58 @@ SalLayout* OutputDevice::ImplLayout( const String& rOrigStr,
     return pSalLayout;
 }
 
+void OutputDevice::forceFallbackFontToFit(SalLayout &rFallback, ImplFontEntry &rFallbackFont,
+    ImplFontSelectData &rFontSelData, int nFallbackLevel,
+    ImplLayoutArgs& rLayoutArgs, const ImplFontMetricData& rOrigMetric) const
+{
+    Rectangle aBoundRect;
+    bool bHaveBounding = false;
+    Rectangle aRectangle;
+
+    rFallback.AdjustLayout( rLayoutArgs );
+
+    //All we care about here is getting the vertical bounds of this text and
+    //make sure it will fit inside the available space
+    Point aPos;
+    for( int nStart = 0;;)
+    {
+        sal_GlyphId nLGlyph;
+        if( !rFallback.GetNextGlyphs( 1, &nLGlyph, aPos, nStart ) )
+            break;
+
+        int nFontTag = nFallbackLevel << GF_FONTSHIFT;
+        nLGlyph |= nFontTag;
+
+        // get bounding rectangle of individual glyph
+        if( mpGraphics->GetGlyphBoundRect( nLGlyph, aRectangle ) )
+        {
+            // merge rectangle
+            aRectangle += aPos;
+            aBoundRect.Union( aRectangle );
+            bHaveBounding = true;
+        }
+    }
+
+    //Shrink it down if it won't fit
+    if (bHaveBounding)
+    {
+        long  nGlyphsAscent = -aBoundRect.Top();
+        float fScaleTop = nGlyphsAscent > rOrigMetric.mnAscent ?
+            rOrigMetric.mnAscent/(float)nGlyphsAscent : 1;
+        long  nGlyphsDescent = aBoundRect.Bottom();
+        float fScaleBottom = nGlyphsDescent > rOrigMetric.mnDescent ?
+            rOrigMetric.mnDescent/(float)nGlyphsDescent : 1;
+        float fScale = fScaleBottom < fScaleTop ? fScaleBottom : fScaleTop;
+        if (fScale < 1)
+        {
+            long nOrigHeight = rFontSelData.mnHeight;
+            rFontSelData.mnHeight *= fScale;
+            rFallbackFont.mnSetFontFlags = mpGraphics->SetFont( &rFontSelData, nFallbackLevel );
+            rFontSelData.mnHeight = nOrigHeight;
+        }
+    }
+}
+
 // -----------------------------------------------------------------------
 
 SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLayoutArgs& rLayoutArgs ) const
@@ -6072,22 +6124,7 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
             }
         }
 
-        ImplFontMetricData aSubstituteMetric(aFontSelData);
         pFallbackFont->mnSetFontFlags = mpGraphics->SetFont( &aFontSelData, nFallbackLevel );
-        mpGraphics->GetFontMetric(&aSubstituteMetric, nFallbackLevel);
-
-        long nOriginalHeight = aOrigMetric.mnAscent + aOrigMetric.mnDescent;
-        long nSubstituteHeight = aSubstituteMetric.mnAscent + aSubstituteMetric.mnDescent;
-        //Too tall, shrink it a bit. Need a better calculation to include extra
-        //factors and any extra wriggle room we might have available ?
-        if (nSubstituteHeight > nOriginalHeight)
-        {
-            float fScale = nOriginalHeight/(float)nSubstituteHeight;
-            long nOrigHeight = aFontSelData.mnHeight;
-            aFontSelData.mnHeight *= fScale;
-            pFallbackFont->mnSetFontFlags = mpGraphics->SetFont( &aFontSelData, nFallbackLevel );
-            aFontSelData.mnHeight = nOrigHeight;
-        }
 
         // create and add glyph fallback layout to multilayout
         rLayoutArgs.ResetPos();
@@ -6096,6 +6133,9 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
         {
             if( pFallback->LayoutText( rLayoutArgs ) )
             {
+                forceFallbackFontToFit(*pFallback, *pFallbackFont, aFontSelData,
+                    nFallbackLevel, rLayoutArgs, aOrigMetric);
+
                 if( !pMultiSalLayout )
                     pMultiSalLayout = new MultiSalLayout( *pSalLayout );
                 pMultiSalLayout->AddFallback( *pFallback,
commit f6733d3f2ccc7b6a8da8752ad14bfd939acb3fa2
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Mar 9 09:07:21 2011 +0000

    cppcheck: this method can be const

diff --git a/vcl/source/gdi/impvect.cxx b/vcl/source/gdi/impvect.cxx
index 5cd2c4c..6feb32b 100644
--- a/vcl/source/gdi/impvect.cxx
+++ b/vcl/source/gdi/impvect.cxx
@@ -363,7 +363,7 @@ public:
     inline void		ImplAdd( BYTE nCode );
     void			ImplEndAdd( ULONG nTypeFlag );
 
-    const Polygon&	ImplGetPoly() { return maPoly; }
+    const Polygon&	ImplGetPoly() const { return maPoly; }
 };
 
 // -----------------------------------------------------------------------------


More information about the Libreoffice-commits mailing list