[Libreoffice-commits] core.git: Branch 'feature/commonsallayout' - 7 commits - configure.ac vcl/headless vcl/inc vcl/Library_vcl.mk vcl/quartz vcl/README.vars vcl/source vcl/unx vcl/win

Akash Jain akash96j at gmail.com
Fri Jun 24 18:53:03 UTC 2016


Rebased ref, commits from common ancestor:
commit 5dad86cf8b7cc925a00ab0dd778541b97110ea7e
Author: Akash Jain <akash96j at gmail.com>
Date:   Mon Jun 20 23:49:53 2016 +0530

    GSoC: Integrate CommonSalLayout in unx/ code path
    
    Change-Id: I7591d4b159d2d92027dba162b5752468cb69e7a7

diff --git a/vcl/README.vars b/vcl/README.vars
index bf85485..b72d499 100644
--- a/vcl/README.vars
+++ b/vcl/README.vars
@@ -6,6 +6,7 @@ SAL_USE_VCLPLUGIN - use a VCL plugin
 SAL_NO_NWF - disable native widgets
 SAL_FORCEDPI - force a specific DPI (gtk & gtk3 plugins only)
 SAL_FORCE_HC - force high-contrast mode
+SAL_USE_COMMON_LAYOUT - use CommonSalLayout layout engine for text layout
 
 VCL_DOUBLEBUFFERING_AVOID_PAINT - don't paint the buffer, useful to see where we do direct painting
 VCL_DOUBLEBUFFERING_FORCE_ENABLE - enable double buffered painting
diff --git a/vcl/headless/svptext.cxx b/vcl/headless/svptext.cxx
index e8fd525..1a523bb 100644
--- a/vcl/headless/svptext.cxx
+++ b/vcl/headless/svptext.cxx
@@ -116,9 +116,14 @@ SalLayout* SvpSalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLe
     return m_aTextRenderImpl.GetTextLayout(rArgs, nFallbackLevel);
 }
 
-void SvpSalGraphics::DrawServerFontLayout( const ServerFontLayout& rSalLayout )
+void SvpSalGraphics::DrawServerFontLayout( const GenericSalLayout& rSalLayout, const ServerFont& rServerFont )
 {
-    m_aTextRenderImpl.DrawServerFontLayout(rSalLayout );
+    m_aTextRenderImpl.DrawServerFontLayout( rSalLayout, rServerFont );
+}
+
+void SvpSalGraphics::DrawCommonSalLayout( const CommonSalLayout& rSalLayout )
+{
+    m_aTextRenderImpl.DrawCommonSalLayout( rSalLayout );
 }
 
 void SvpSalGraphics::SetTextColor( SalColor nSalColor )
diff --git a/vcl/inc/CommonSalLayout.hxx b/vcl/inc/CommonSalLayout.hxx
index 0d941f9..6d6d19e 100755
--- a/vcl/inc/CommonSalLayout.hxx
+++ b/vcl/inc/CommonSalLayout.hxx
@@ -36,6 +36,9 @@ class CommonSalLayout : public GenericSalLayout
     css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
 #ifdef _WIN32
     HDC mhDC;
+#elif defined(MACOSX) || defined(IOS)
+#else
+    ServerFont& mrServerFont;
 #endif
 
 public:
@@ -45,7 +48,9 @@ public:
     explicit                CommonSalLayout(const CoreTextStyle*);
 #else
     explicit                CommonSalLayout(ServerFont&);
+    ServerFont&             GetServerFont() const {return mrServerFont;}
 #endif
+
     virtual                 ~CommonSalLayout();
     void                    SetNeedFallback(ImplLayoutArgs&, sal_Int32, bool);
     void                    AdjustLayout(ImplLayoutArgs&) override;
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
index dc88a60..40bc0b207 100644
--- a/vcl/inc/headless/svpgdi.hxx
+++ b/vcl/inc/headless/svpgdi.hxx
@@ -46,6 +46,7 @@
 struct BitmapBuffer;
 class GlyphCache;
 class ServerFont;
+class CommonSalLayout;
 typedef struct _cairo cairo_t;
 typedef struct _cairo_surface cairo_surface_t;
 typedef struct _cairo_user_data_key cairo_user_data_key_t;
@@ -152,7 +153,8 @@ public:
     virtual bool            GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) override;
     virtual bool            GetGlyphOutline( sal_GlyphId nIndex, basegfx::B2DPolyPolygon& ) override;
     virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void            DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void            DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
+    virtual void            DrawCommonSalLayout( const CommonSalLayout& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
     virtual void            drawPixel( long nX, long nY ) override;
     virtual void            drawPixel( long nX, long nY, SalColor nSalColor ) override;
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 09dc619..0e55a89 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -402,7 +402,7 @@ public:
     virtual bool            GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) override;
 
     virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void            DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void            DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
 
 #ifdef MACOSX
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 56fe42d..4701cf2 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -44,6 +44,8 @@ class FontSubsetInfo;
 class OpenGLContext;
 class OutputDevice;
 class ServerFontLayout;
+class ServerFont;
+class CommonSalLayout;
 struct SystemGraphicsData;
 
 #if ENABLE_CAIRO_CANVAS
@@ -217,7 +219,8 @@ public:
     virtual bool                GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) = 0;
 
     virtual SalLayout*          GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
-    virtual void                DrawServerFontLayout( const ServerFontLayout& ) = 0;
+    virtual void                DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) = 0;
+    virtual void                DrawCommonSalLayout( const CommonSalLayout& ) = 0;
 
     virtual bool                supportsOperation( OutDevSupportType ) const = 0;
 
diff --git a/vcl/inc/textrender.hxx b/vcl/inc/textrender.hxx
index e08274e..01775f5 100644
--- a/vcl/inc/textrender.hxx
+++ b/vcl/inc/textrender.hxx
@@ -27,6 +27,7 @@
 class ImplLayoutArgs;
 class ImplFontMetricData;
 class ServerFontLayout;
+class CommonSalLayout;
 class PhysicalFontCollection;
 class PhysicalFontFace;
 
@@ -71,7 +72,8 @@ public:
     virtual bool                    GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) = 0;
     virtual bool                    GetGlyphOutline( sal_GlyphId nIndex, basegfx::B2DPolyPolygon& ) = 0;
     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
-    virtual void                    DrawServerFontLayout( const ServerFontLayout& ) = 0;
+    virtual void                    DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) = 0;
+    virtual void                    DrawCommonSalLayout( const CommonSalLayout& ) = 0;
 #if ENABLE_CAIRO_CANVAS
     virtual SystemFontData          GetSysFontData( int nFallbackLevel ) const = 0;
 #endif // ENABLE_CAIRO_CANVAS
diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx
index 612daae..2c287ef 100644
--- a/vcl/inc/unx/cairotextrender.hxx
+++ b/vcl/inc/unx/cairotextrender.hxx
@@ -29,6 +29,7 @@
 typedef struct FT_FaceRec_* FT_Face;
 
 class ServerFont;
+class CommonSalLayout;
 class GlyphCache;
 typedef struct _cairo cairo_t;
 
@@ -118,7 +119,8 @@ public:
     virtual bool                GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) override;
     virtual bool                GetGlyphOutline( sal_GlyphId nIndex, basegfx::B2DPolyPolygon& ) override;
     virtual SalLayout*          GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void                DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void                DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
+    virtual void                DrawCommonSalLayout( const CommonSalLayout& ) override;
 #if ENABLE_CAIRO_CANVAS
     virtual SystemFontData      GetSysFontData( int nFallbackLevel ) const override;
 #endif
diff --git a/vcl/inc/unx/genpspgraphics.h b/vcl/inc/unx/genpspgraphics.h
index b7658b9..590b72d 100644
--- a/vcl/inc/unx/genpspgraphics.h
+++ b/vcl/inc/unx/genpspgraphics.h
@@ -131,7 +131,9 @@ public:
     virtual bool            GetGlyphBoundRect( sal_GlyphId, Rectangle& ) override;
     virtual bool            GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) override;
     virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void            DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void            DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
+    virtual void            DrawServerFontLayout( const ServerFontLayout& );
+    virtual void            DrawCommonSalLayout( const CommonSalLayout& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
     virtual void            drawPixel( long nX, long nY ) override;
     virtual void            drawPixel( long nX, long nY, SalColor nSalColor ) override;
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index 40aa91b..a06ae2f 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -55,6 +55,7 @@ class X11OpenGLSalVirtualDevice;
 class ServerFont;
 class ImplLayoutArgs;
 class ServerFontLayout;
+class CommonSalLayout;
 class PhysicalFontCollection;
 class PhysicalFontFace;
 class SalGraphicsImpl;
@@ -154,7 +155,8 @@ public:
     virtual bool                    GetGlyphBoundRect( sal_GlyphId nIndex, Rectangle& ) override;
     virtual bool                    GetGlyphOutline( sal_GlyphId nIndex, basegfx::B2DPolyPolygon& ) override;
     virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void                    DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void                    DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
+    virtual void                    DrawCommonSalLayout( const CommonSalLayout& ) override;
 
     virtual bool                    supportsOperation( OutDevSupportType ) const override;
     virtual void                    drawPixel( long nX, long nY ) override;
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index b6e8cce..ba79050 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -451,7 +451,7 @@ public:
     virtual bool            GetGlyphOutline( sal_GlyphId, basegfx::B2DPolyPolygon& ) override;
 
     virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
-    virtual void            DrawServerFontLayout( const ServerFontLayout& ) override;
+    virtual void            DrawServerFontLayout( const GenericSalLayout&, const ServerFont& ) override;
 
     virtual bool            supportsOperation( OutDevSupportType ) const override;
     // Query the platform layer for control support
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 6c62b81..14a5e8b 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -413,7 +413,7 @@ bool AquaSalGraphics::GetGlyphBoundRect( sal_GlyphId aGlyphId, Rectangle& rRect
     return bRC;
 }
 
-void AquaSalGraphics::DrawServerFontLayout( const ServerFontLayout& )
+void AquaSalGraphics::DrawServerFontLayout( const GenericSalLayout&, const ServerFont& )
 {
 }
 
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index fb1111f..4c1eb44 100755
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -24,6 +24,7 @@
 #include <com/sun/star/i18n/CharacterIteratorMode.hpp>
 #include <i18nlangtag/mslangid.hxx>
 #include <limits>
+#include <salgdi.hxx>
 
 #if defined(_WIN32)
 struct WinFontFaceWithHDC
@@ -97,7 +98,8 @@ CommonSalLayout::CommonSalLayout(CoreTextStyle* pCoreTextStyle)
 #else
 CommonSalLayout::CommonSalLayout(ServerFont& rServerFont)
 :   mpHBFace(nullptr),
-    maFontSelData(rServerFont.GetFontSelData())
+    maFontSelData(rServerFont.GetFontSelData()),
+    mrServerFont(rServerFont)
 {
     mpHBFace = hb_face_create_for_tables(getFontTable, &rServerFont, nullptr);
 }
@@ -194,9 +196,14 @@ void CommonSalLayout::AdjustLayout(ImplLayoutArgs& rArgs)
 //XXX Kashida
 }
 
-void CommonSalLayout::DrawText( SalGraphics& ) const
+void CommonSalLayout::DrawText(SalGraphics& rSalGraphics) const
 {
     //call platform dependent DrawText functions
+#if defined(_WIN32)
+#elif defined(MACOSX) || defined(IOS)
+#else
+    rSalGraphics.DrawServerFontLayout( *this, mrServerFont );
+#endif
 }
 
 bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
@@ -204,9 +211,10 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
     //XXX WinLayout object DOESN'T derive from GSL
     GenericSalLayout& rLayout = *this;
 
-    hb_font_t* pHBFont = hb_font_create(mpHBFace);
-    hb_font_set_ppem(pHBFont, maFontSelData.mnWidth, maFontSelData.mnHeight);
-    hb_font_set_scale(pHBFont, maFontSelData.mnWidth << 6, maFontSelData.mnHeight << 6);
+    hb_font_t *pHBFont = hb_font_create(mpHBFace);
+    hb_font_set_ppem(pHBFont, maFontSelData.mnWidth? maFontSelData.mnWidth:maFontSelData.mnHeight , maFontSelData.mnHeight);
+    hb_font_set_scale(pHBFont, (uint64_t)(maFontSelData.mnWidth? maFontSelData.mnWidth:maFontSelData.mnHeight) << 6
+                             , (uint64_t)maFontSelData.mnHeight << 6);
     hb_ot_font_set_funcs(pHBFont);
 
     int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos);
@@ -374,7 +382,6 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
                 int32_t nYOffset =  pHbPositions[i].y_offset >> 6;
                 int32_t nXAdvance = pHbPositions[i].x_advance >> 6;
                 int32_t nYAdvance = pHbPositions[i].y_advance >> 6;
-
                 Point aNewPos = Point(aCurrPos.X() + nXOffset, -(aCurrPos.Y() + nYOffset));
                 // Definiton of glyphitem may have to change to support system graphics lib
                 const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance, nXOffset);
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 513f5e5..d404373 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -42,6 +42,7 @@
 
 #include <cairo.h>
 #include <cairo-ft.h>
+#include "CommonSalLayout.hxx"
 
 CairoTextRender::CairoTextRender()
     : mnTextColor(MAKE_SALCOLOR(0x00, 0x00, 0x00)) //black
@@ -151,8 +152,11 @@ namespace
         return (3600 - (nDegree10th)) * M_PI / 1800.0;
     }
 }
+void CairoTextRender::DrawCommonSalLayout( const CommonSalLayout& )
+{
+}
 
-void CairoTextRender::DrawServerFontLayout( const ServerFontLayout& rLayout )
+void CairoTextRender::DrawServerFontLayout( const GenericSalLayout& rLayout, const ServerFont& rServerFont )
 {
     std::vector<cairo_glyph_t> cairo_glyphs;
     std::vector<int> glyph_extrarotation;
@@ -185,7 +189,7 @@ void CairoTextRender::DrawServerFontLayout( const ServerFontLayout& rLayout )
     if (cairo_glyphs.empty())
         return;
 
-    ServerFont& rFont = rLayout.GetServerFont();
+    const ServerFont& rFont = rServerFont;
     const FontSelectPattern& rFSD = rFont.GetFontSelData();
     int nHeight = rFSD.mnHeight;
     int nWidth = rFSD.mnWidth ? rFSD.mnWidth : nHeight;
@@ -507,7 +511,14 @@ SalLayout* CairoTextRender::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackL
         }
         else
 #endif
-            pLayout = new ServerFontLayout( *mpServerFont[ nFallbackLevel ] );
+            if(getenv("SAL_USE_COMMON_LAYOUT"))
+            {
+                pLayout = new CommonSalLayout( *mpServerFont[ nFallbackLevel ] );
+            }
+            else
+            {
+                pLayout = new ServerFontLayout( *mpServerFont[ nFallbackLevel ] );
+            }
     }
 
     return pLayout;
diff --git a/vcl/unx/generic/gdi/font.cxx b/vcl/unx/generic/gdi/font.cxx
index 1669465..12c5ec3 100644
--- a/vcl/unx/generic/gdi/font.cxx
+++ b/vcl/unx/generic/gdi/font.cxx
@@ -52,9 +52,13 @@ X11SalGraphics::GetFontGC()
     return pFontGC_;
 }
 
-void X11SalGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
+void X11SalGraphics::DrawServerFontLayout( const GenericSalLayout& rLayout, const ServerFont& rServerFont )
 {
-    mxTextRenderImpl->DrawServerFontLayout(rLayout);
+    mxTextRenderImpl->DrawServerFontLayout(rLayout, rServerFont);
+}
+void X11SalGraphics::DrawCommonSalLayout( const CommonSalLayout& rLayout )
+{
+    mxTextRenderImpl->DrawCommonSalLayout(rLayout);
 }
 
 const FontCharMapPtr X11SalGraphics::GetFontCharMap() const
diff --git a/vcl/unx/generic/glyphs/gcach_layout.cxx b/vcl/unx/generic/glyphs/gcach_layout.cxx
index dc9a84f..b69721b 100644
--- a/vcl/unx/generic/glyphs/gcach_layout.cxx
+++ b/vcl/unx/generic/glyphs/gcach_layout.cxx
@@ -47,7 +47,7 @@ ServerFontLayout::ServerFontLayout( ServerFont& rFont )
 
 void ServerFontLayout::DrawText( SalGraphics& rSalGraphics ) const
 {
-    rSalGraphics.DrawServerFontLayout( *this );
+    rSalGraphics.DrawServerFontLayout( *this , mrServerFont );
 }
 
 bool ServerFontLayout::LayoutText( ImplLayoutArgs& rArgs )
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index 78eee82..5af4388 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -761,6 +761,14 @@ void PspFontLayout::DrawText( SalGraphics& ) const
     DrawPrinterLayout( *this, mrPrinterGfx, false );
 }
 
+void GenPspGraphics::DrawServerFontLayout( const GenericSalLayout&, const ServerFont& )
+{
+}
+
+void GenPspGraphics::DrawCommonSalLayout( const CommonSalLayout& )
+{
+}
+
 void GenPspGraphics::DrawServerFontLayout( const ServerFontLayout& rLayout )
 {
     // print complex text
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index 4c8865e..197a333 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -2606,7 +2606,7 @@ void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
     }
 }
 
-void WinSalGraphics::DrawServerFontLayout( const ServerFontLayout& )
+void WinSalGraphics::DrawServerFontLayout( const GenericSalLayout&, const ServerFont& )
 {}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 9ba430e8eda9f463fd78284778c2f2eb81671bf1
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 14:52:16 2016 +0530

    GSoC: Modify HARFBUZZ_LIBS flag if compiling with MSVC
    
    MSVC has a different format for specifying libs to be linked.
    Therefore, modify libs flag accordingly.
    
    Change-Id: Ib919c4b6b0cdac47a8a6ad6730d20e19bc05b0d4

diff --git a/configure.ac b/configure.ac
index b9565a9..e0993b4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -9219,6 +9219,9 @@ if test "$with_harfbuzz" = "yes" -o \( $_os != WINNT -a $_os != Darwin -a $_os !
     else
         libo_CHECK_SYSTEM_MODULE([harfbuzz],[HARFBUZZ],[harfbuzz >= 0.9.10],[-I${WORKDIR}/UnpackedTarball/harfbuzz/src],["-L${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs -lharfbuzz -lharfbuzz-icu"])
     fi
+    if test "$COM" = "MSC"; then # override the above
+        HARFBUZZ_LIBS="${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs/libharfbuzz.lib ${WORKDIR}/UnpackedTarball/harfbuzz/src/.libs/libharfbuzz-icu.lib"
+    fi
 else
     AC_MSG_RESULT([no])
 fi
commit 02008d5b814520df3d93d28a6c54ecf83392e4c5
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 14:38:12 2016 +0530

    GSoC: New CommonSalLayout class created
    
    Change-Id: Ic11e573da2f5fd6ef931f53ab674f8894815c3b4

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index a43402b..026a42d 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -299,6 +299,8 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/gdi/textlayout \
     vcl/source/gdi/virdev \
     vcl/source/gdi/wall \
+    vcl/source/gdi/scrptrun \
+    vcl/source/gdi/CommonSalLayout \
     vcl/source/bitmap/bitmapfilter \
     vcl/source/bitmap/bitmapscalesuper \
     vcl/source/bitmap/BitmapScaleConvolution \
diff --git a/vcl/inc/CommonSalLayout.hxx b/vcl/inc/CommonSalLayout.hxx
new file mode 100755
index 0000000..0d941f9
--- /dev/null
+++ b/vcl/inc/CommonSalLayout.hxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifdef _WIN32
+#include "win/winlayout.hxx"
+#elif defined(MACOSX) || defined(IOS)
+// TODO add quartz headers
+#else
+#include "unx/freetype_glyphcache.hxx"
+#endif
+
+#include <sallayout.hxx>
+#include <hb-icu.h>
+#include <hb-ot.h>
+
+class CommonSalLayout : public GenericSalLayout
+{
+    hb_face_t* mpHBFace;
+    FontSelectPattern maFontSelData;
+    css::uno::Reference<css::i18n::XBreakIterator> mxBreak;
+#ifdef _WIN32
+    HDC mhDC;
+#endif
+
+public:
+#if defined(_WIN32)
+    explicit                CommonSalLayout(HDC, const WinFontFace&, WinFontInstance&);
+#elif defined(MACOSX) || defined(IOS)
+    explicit                CommonSalLayout(const CoreTextStyle*);
+#else
+    explicit                CommonSalLayout(ServerFont&);
+#endif
+    virtual                 ~CommonSalLayout();
+    void                    SetNeedFallback(ImplLayoutArgs&, sal_Int32, bool);
+    void                    AdjustLayout(ImplLayoutArgs&) override;
+    virtual bool            LayoutText(ImplLayoutArgs&) override;
+    virtual void            DrawText( SalGraphics& ) const override;
+    std::shared_ptr<vcl::TextLayoutCache> CreateTextLayoutCache(OUString const&) const override;
+};
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
new file mode 100755
index 0000000..fb1111f
--- /dev/null
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -0,0 +1,401 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include "CommonSalLayout.hxx"
+
+#include <vcl/unohelp.hxx>
+#include <scrptrun.h>
+#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
+#include <i18nlangtag/mslangid.hxx>
+#include <limits>
+
+#if defined(_WIN32)
+struct WinFontFaceWithHDC
+{
+    const WinFontFace& mrWinFontFace;
+    HDC                mhDC;
+    WinFontFaceWithHDC(const WinFontFace& rWFF, HDC hDC)
+    :    mrWinFontFace(rWFF),
+         mhDC(hDC)
+    {}
+};
+#endif
+
+static hb_blob_t *getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
+{
+    char pTagName[5];
+    pTagName[0] = (char)(nTableTag >> 24);
+    pTagName[1] = (char)(nTableTag >> 16);
+    pTagName[2] = (char)(nTableTag >>  8);
+    pTagName[3] = (char)(nTableTag);
+    pTagName[4] = 0;
+
+    sal_uLong nLength=0;
+    const unsigned char* pBuffer = nullptr;
+#if defined(_WIN32)
+    WinFontFaceWithHDC* pWinFontFaceWithHDC = static_cast<WinFontFaceWithHDC*>(pUserData);
+    nLength = pWinFontFaceWithHDC->mrWinFontFace.GetTable(pTagName, pBuffer, pWinFontFaceWithHDC->mhDC);
+#elif defined(MACOSX) || defined(IOS)
+    CoreTextFontFace* pFont = static_cast<CoreTextFontFace*>(pUserData);
+    nLength = pFont->GetFontTable(pTagName, pBuffer);
+#else
+    ServerFont* pFont = static_cast<ServerFont*>(pUserData);
+    pBuffer = pFont->GetTable(pTagName, &nLength);
+#endif
+
+    hb_blob_t* pBlob = nullptr;
+    if (pBuffer != nullptr)
+        pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY, const_cast<unsigned char *>(pBuffer), nullptr);
+
+    return pBlob;
+}
+
+static hb_unicode_funcs_t* getUnicodeFuncs()
+{
+    static hb_unicode_funcs_t* ufuncs = hb_unicode_funcs_create(hb_icu_get_unicode_funcs());
+#if !HB_VERSION_ATLEAST(1, 1, 0)
+    hb_unicode_funcs_set_decompose_compatibility_func(ufuncs, unicodeDecomposeCompatibility, nullptr, nullptr);
+#endif
+    return ufuncs;
+}
+
+#if defined(_WIN32)
+CommonSalLayout::CommonSalLayout(HDC hDC, const WinFontFace& rWinFontFace, WinFontInstance& rWinFontInstance)
+:   mhDC(hDC),
+    mpHBFace(nullptr),
+    maFontSelData(rWinFontInstance.maFontSelData)
+{
+    WinFontFaceWithHDC rWinFontFaceWithHDC(rWinFontFace, mhDC);
+    mpHBFace = hb_face_create_for_tables(getFontTable, &rWinFontFaceWithHDC, nullptr);
+}
+
+#elif defined(MACOSX) || defined(IOS)
+CommonSalLayout::CommonSalLayout(CoreTextStyle* pCoreTextStyle)
+:   mpHBFace(nullptr),
+    maFontSelData(pCoreTextStyle)
+{
+    mpHBFace = hb_face_create_for_tables(getFontTable, pCoreTextStyle->mpFontData, nullptr);
+    //XXX modify coretextstyle to also store fsd
+}
+
+#else
+CommonSalLayout::CommonSalLayout(ServerFont& rServerFont)
+:   mpHBFace(nullptr),
+    maFontSelData(rServerFont.GetFontSelData())
+{
+    mpHBFace = hb_face_create_for_tables(getFontTable, &rServerFont, nullptr);
+}
+#endif
+
+CommonSalLayout::~CommonSalLayout()
+{
+    hb_face_destroy(mpHBFace);
+}
+
+struct HbScriptRun
+{
+    int32_t mnMin;
+    int32_t mnEnd;
+    hb_script_t maScript;
+
+    HbScriptRun(int32_t nMin, int32_t nEnd, UScriptCode aScript)
+    : mnMin(nMin), mnEnd(nEnd),
+      maScript(hb_icu_script_to_script(aScript))
+    {}
+};
+
+typedef std::vector<HbScriptRun> HbScriptRuns;
+
+namespace vcl {
+    struct Run
+    {
+        int32_t nStart;
+        int32_t nEnd;
+        UScriptCode nCode;
+        Run(int32_t nStart_, int32_t nEnd_, UScriptCode nCode_)
+            : nStart(nStart_), nEnd(nEnd_), nCode(nCode_)
+        {}
+    };
+
+    class TextLayoutCache
+    {
+    public:
+        std::vector<vcl::Run> runs;
+        TextLayoutCache(sal_Unicode const* pStr, sal_Int32 const nEnd)
+        {
+            vcl::ScriptRun aScriptRun(
+                reinterpret_cast<const UChar *>(pStr),
+                nEnd);
+            while (aScriptRun.next())
+            {
+                runs.push_back(Run(aScriptRun.getScriptStart(),
+                    aScriptRun.getScriptEnd(), aScriptRun.getScriptCode()));
+            }
+        }
+    };
+}
+
+std::shared_ptr<vcl::TextLayoutCache> CommonSalLayout::CreateTextLayoutCache(OUString const& rString) const
+{
+    return std::make_shared<vcl::TextLayoutCache>(rString.getStr(), rString.getLength());
+}
+
+void CommonSalLayout::SetNeedFallback(ImplLayoutArgs& rArgs, sal_Int32 nCharPos, bool bRightToLeft)
+{
+    if (nCharPos < 0)
+        return;
+
+    using namespace ::com::sun::star;
+
+    if (!mxBreak.is())
+        mxBreak = vcl::unohelper::CreateBreakIterator();
+
+    lang::Locale aLocale(rArgs.maLanguageTag.getLocale());
+
+    //if position nCharPos is missing in the font, grab the entire grapheme and
+    //mark all glyphs as missing so the whole thing is rendered with the same
+    //font
+    sal_Int32 nDone;
+    sal_Int32 nGraphemeStartPos =
+        mxBreak->previousCharacters(rArgs.mrStr, nCharPos+1, aLocale,
+            i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
+    sal_Int32 nGraphemeEndPos =
+        mxBreak->nextCharacters(rArgs.mrStr, nCharPos, aLocale,
+            i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
+
+    rArgs.NeedFallback(nGraphemeStartPos, nGraphemeEndPos, bRightToLeft);
+}
+
+void CommonSalLayout::AdjustLayout(ImplLayoutArgs& rArgs)
+{
+    GenericSalLayout::AdjustLayout(rArgs);
+
+    // apply asian kerning if the glyphs are not already formatted
+    if( (rArgs.mnFlags & SalLayoutFlags::KerningAsian)
+    && !(rArgs.mnFlags & SalLayoutFlags::Vertical) )
+        if( (rArgs.mpDXArray != nullptr) || (rArgs.mnLayoutWidth != 0) )
+            ApplyAsianKerning(rArgs.mrStr);
+//XXX Kashida
+}
+
+void CommonSalLayout::DrawText( SalGraphics& ) const
+{
+    //call platform dependent DrawText functions
+}
+
+bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
+{
+    //XXX WinLayout object DOESN'T derive from GSL
+    GenericSalLayout& rLayout = *this;
+
+    hb_font_t* pHBFont = hb_font_create(mpHBFace);
+    hb_font_set_ppem(pHBFont, maFontSelData.mnWidth, maFontSelData.mnHeight);
+    hb_font_set_scale(pHBFont, maFontSelData.mnWidth << 6, maFontSelData.mnHeight << 6);
+    hb_ot_font_set_funcs(pHBFont);
+
+    int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos);
+    rLayout.Reserve(nGlyphCapacity);
+
+    const int nLength = rArgs.mrStr.getLength();
+    const sal_Unicode *pStr = rArgs.mrStr.getStr();
+
+    std::unique_ptr<vcl::TextLayoutCache> pNewScriptRun;
+    vcl::TextLayoutCache const* pTextLayout;
+    if (rArgs.m_pTextLayoutCache)
+    {
+        pTextLayout = rArgs.m_pTextLayoutCache; // use cache!
+    }
+    else
+    {
+        pNewScriptRun.reset(new vcl::TextLayoutCache(pStr, rArgs.mnEndCharPos));
+        pTextLayout = pNewScriptRun.get();
+    }
+
+    Point aCurrPos(0, 0);
+    while (true)
+    {
+        int nBidiMinRunPos, nBidiEndRunPos;
+        bool bRightToLeft;
+        if (!rArgs.GetNextRun(&nBidiMinRunPos, &nBidiEndRunPos, &bRightToLeft))
+            break;
+
+        // Find script subruns.
+        int nCurrentPos = nBidiMinRunPos;
+        HbScriptRuns aScriptSubRuns;
+        size_t k = 0;
+        for (; k < pTextLayout->runs.size(); ++k)
+        {
+            vcl::Run const& rRun(pTextLayout->runs[k]);
+            if (rRun.nStart <= nCurrentPos && nCurrentPos < rRun.nEnd)
+            {
+                break;
+            }
+        }
+
+        while (nCurrentPos < nBidiEndRunPos && k < pTextLayout->runs.size())
+        {
+            int32_t nMinRunPos = nCurrentPos;
+            int32_t nEndRunPos = std::min(pTextLayout->runs[k].nEnd, nBidiEndRunPos);
+            HbScriptRun aRun(nMinRunPos, nEndRunPos, pTextLayout->runs[k].nCode);
+            aScriptSubRuns.push_back(aRun);
+
+            nCurrentPos = nEndRunPos;
+            ++k;
+        }
+
+        // RTL subruns should be reversed to ensure that final glyph order is
+        // correct.
+        if (bRightToLeft)
+            std::reverse(aScriptSubRuns.begin(), aScriptSubRuns.end());
+
+        for (HbScriptRuns::iterator it = aScriptSubRuns.begin(); it != aScriptSubRuns.end(); ++it)
+        {
+            int nMinRunPos = it->mnMin;
+            int nEndRunPos = it->mnEnd;
+            int nRunLen = nEndRunPos - nMinRunPos;
+            hb_script_t aHbScript = it->maScript;
+            // hb_language_from_string() accept ISO639-3 language tag except for Chinese.
+            LanguageTag &rTag = rArgs.maLanguageTag;
+            OString sLanguage = OUStringToOString( MsLangId::isChinese(rTag.getLanguageType()) ? rTag.getBcp47():rTag.getLanguage() , RTL_TEXTENCODING_UTF8 );
+
+            int nHbFlags = HB_BUFFER_FLAGS_DEFAULT;
+            if (nMinRunPos == 0)
+                nHbFlags |= HB_BUFFER_FLAG_BOT; /* Beginning-of-text */
+            if (nEndRunPos == nLength)
+                nHbFlags |= HB_BUFFER_FLAG_EOT; /* End-of-text */
+
+            hb_buffer_t *pHbBuffer = hb_buffer_create();
+            static hb_unicode_funcs_t* pHbUnicodeFuncs = getUnicodeFuncs();
+#if !HB_VERSION_ATLEAST(1, 1, 0)
+            hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs);
+#endif
+            hb_buffer_set_direction(pHbBuffer, bRightToLeft ? HB_DIRECTION_RTL: HB_DIRECTION_LTR);
+            hb_buffer_set_script(pHbBuffer, aHbScript);
+            hb_buffer_set_language(pHbBuffer, hb_language_from_string(sLanguage.getStr(), -1));
+            hb_buffer_set_flags(pHbBuffer, (hb_buffer_flags_t) nHbFlags);
+            hb_buffer_add_utf16(
+                pHbBuffer, reinterpret_cast<uint16_t const *>(pStr), nLength,
+                nMinRunPos, nRunLen);
+#if HB_VERSION_ATLEAST(0, 9, 42)
+            hb_buffer_set_cluster_level(pHbBuffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
+#endif
+            hb_shape(pHBFont, pHbBuffer, nullptr, 0);
+
+            int nRunGlyphCount = hb_buffer_get_length(pHbBuffer);
+            hb_glyph_info_t *pHbGlyphInfos = hb_buffer_get_glyph_infos(pHbBuffer, nullptr);
+            hb_glyph_position_t *pHbPositions = hb_buffer_get_glyph_positions(pHbBuffer, nullptr);
+
+            sal_Int32 nGraphemeStartPos = std::numeric_limits<sal_Int32>::max();
+            sal_Int32 nGraphemeEndPos = std::numeric_limits<sal_Int32>::min();
+            com::sun::star::lang::Locale aLocale(rArgs.maLanguageTag.getLocale());
+            if (!mxBreak.is())
+                mxBreak = vcl::unohelper::CreateBreakIterator();
+
+            for (int i = 0; i < nRunGlyphCount; ++i) {
+                int32_t nGlyphIndex = pHbGlyphInfos[i].codepoint;
+                int32_t nCharPos = pHbGlyphInfos[i].cluster;
+
+                // if needed request glyph fallback by updating LayoutArgs
+                if (!nGlyphIndex)
+                {
+                    SetNeedFallback(rArgs, nCharPos, bRightToLeft);
+                    if (SalLayoutFlags::ForFallback & rArgs.mnFlags)
+                        continue;
+                }
+
+                sal_Int32 indexUtf16 = nCharPos;
+                sal_UCS4 aChar = rArgs.mrStr.iterateCodePoints(&indexUtf16, 0);
+
+                bool bInCluster = false;
+                if(bRightToLeft && (nCharPos < nGraphemeStartPos))
+                {
+                    sal_Int32 nDone;
+                    nGraphemeStartPos = mxBreak->previousCharacters(rArgs.mrStr, nCharPos+1, aLocale,
+                                                  com::sun::star::i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
+                }
+                else if(!bRightToLeft && (nCharPos >= nGraphemeEndPos))
+                {
+                    sal_Int32 nDone;
+                    nGraphemeEndPos = mxBreak->nextCharacters(rArgs.mrStr, nCharPos, aLocale,
+                                                  com::sun::star::i18n::CharacterIteratorMode::SKIPCELL, 1, nDone);
+                }
+                else
+                {
+                    bInCluster = true;
+                }
+
+                long nGlyphFlags = 0;
+                if (bRightToLeft)
+                    nGlyphFlags |= GlyphItem::IS_RTL_GLYPH;
+
+                if (bInCluster)
+                    nGlyphFlags |= GlyphItem::IS_IN_CLUSTER;
+
+                bool bDiacritic = false;
+                if (hb_ot_layout_has_glyph_classes(mpHBFace))
+                {
+                    // the font has GDEF table
+                    bool bMark = hb_ot_layout_get_glyph_class(mpHBFace, nGlyphIndex) == HB_OT_LAYOUT_GLYPH_CLASS_MARK;
+                    if (bMark && pHbPositions[i].x_advance == 0)
+                        bDiacritic = true;
+                }
+                else
+                {
+#if HB_VERSION_ATLEAST(0, 9, 42)
+                    if(hb_unicode_general_category (pHbUnicodeFuncs, aChar) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
+                        bDiacritic = true;
+#else
+                    // the font lacks GDEF table
+                    if (pHbPositions[i].x_advance == 0)
+                        bDiacritic = true;
+#endif
+                }
+
+                if (bDiacritic)
+                    nGlyphFlags |= GlyphItem::IS_DIACRITIC;
+
+                int32_t nXOffset =  pHbPositions[i].x_offset >> 6;
+                int32_t nYOffset =  pHbPositions[i].y_offset >> 6;
+                int32_t nXAdvance = pHbPositions[i].x_advance >> 6;
+                int32_t nYAdvance = pHbPositions[i].y_advance >> 6;
+
+                Point aNewPos = Point(aCurrPos.X() + nXOffset, -(aCurrPos.Y() + nYOffset));
+                // Definiton of glyphitem may have to change to support system graphics lib
+                const GlyphItem aGI(nCharPos, nGlyphIndex, aNewPos, nGlyphFlags, nXAdvance, nXOffset);
+                rLayout.AppendGlyph(aGI);
+
+                aCurrPos.X() += nXAdvance;
+                aCurrPos.Y() += nYAdvance;
+            }
+
+            hb_buffer_destroy(pHbBuffer);
+        }
+    }
+
+    hb_font_destroy(pHBFont);
+
+    rLayout.SortGlyphItems();
+
+    /* XXX seems to be broken
+    if((rArgs.mpDXArray || rArgs.mnLayoutWidth)
+    && ((maHbScript == HB_SCRIPT_ARABIC) || (maHbScript == HB_SCRIPT_SYRIAC)))
+        rArgs.mnFlags |= SalLayoutFlags::KashidaJustification;
+    */
+    return true;
+}
commit 849a034055e43b122c1ad2ef0727e238ac06d4d1
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 13:46:18 2016 +0530

    GSoC: Move some includes and code from winlayout.cxx to winlayout.hxx
    
    WinFontInstance definition moved to winlayout.hxx. It has to be used
    in the new layout class. Code and headers which WinFontInstance
    depends on also moved to winlayout.hxx
    
    Change-Id: Idc8f87e6601c220d504398671326b1f23d1779a3

diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx
old mode 100644
new mode 100755
index 6709cb1..f92a7b1
--- a/vcl/inc/win/winlayout.hxx
+++ b/vcl/inc/win/winlayout.hxx
@@ -28,15 +28,195 @@
 
 #include <usp10.h>
 
+#include "opengl/PackedTextureAtlas.hxx"
+
+typedef std::unordered_map<int,int> IntMap;
+
 // Graphite headers
 #include <config_graphite.h>
 #if ENABLE_GRAPHITE
 #include <graphite_layout.hxx>
+#include <i18nlangtag/languagetag.hxx>
+#include <graphite_features.hxx>
+#if ENABLE_GRAPHITE_DWRITE
+#include <d2d1.h>
+#include <dwrite.h>
+#endif
 #endif
 
+// This needs to come after any includes for d2d1.h, otherwise we get lots of errors
+#include "glyphy/demo.hxx"
+
 class WinFontInstance;
 struct VisualItem;
 
+namespace
+{
+// Extra space at the top and bottom of the glyph in total = tmHeight / GLYPH_SPACE_RATIO;
+const int GLYPH_SPACE_RATIO = 8;
+// Border size at the top of the glyph = tmHeight / GLYPH_OFFSET_RATIO;
+const int GLYPH_OFFSET_RATIO = GLYPH_SPACE_RATIO * 2;
+}
+
+struct OpenGLGlyphDrawElement
+{
+    Rectangle maLocation;
+    int maLeftOverhangs;
+    OpenGLTexture maTexture;
+    int mnBaselineOffset;
+    int mnHeight;
+    bool mbVertical;
+    bool mbRealGlyphIndices;
+
+    int getExtraSpace() const
+    {
+        return std::max(mnHeight / GLYPH_SPACE_RATIO, 4);
+    }
+
+    int getExtraOffset() const
+    {
+        return std::max(mnHeight / GLYPH_OFFSET_RATIO, 2);
+    }
+};
+
+class GlyphCache;
+
+struct GlobalGlyphCache
+{
+    GlobalGlyphCache()
+        : maPackedTextureAtlas(2048, 2048)
+    {}
+
+    PackedTextureAtlasManager maPackedTextureAtlas;
+    std::unordered_set<GlyphCache*> maGlyphCaches;
+};
+
+class GlyphCache
+{
+private:
+    static std::unique_ptr<GlobalGlyphCache> gGlobalGlyphCache;
+    std::unordered_map<int, OpenGLGlyphDrawElement> maOpenGLTextureCache;
+
+public:
+    GlyphCache()
+    {
+        gGlobalGlyphCache.get()->maGlyphCaches.insert(this);
+    }
+
+    ~GlyphCache()
+    {
+        gGlobalGlyphCache.get()->maGlyphCaches.erase(this);
+    }
+
+    bool ReserveTextureSpace(OpenGLGlyphDrawElement& rElement, int nWidth, int nHeight)
+    {
+        GlobalGlyphCache* pGlobalGlyphCache = gGlobalGlyphCache.get();
+        rElement.maTexture = pGlobalGlyphCache->maPackedTextureAtlas.Reserve(nWidth, nHeight);
+        if (!rElement.maTexture)
+            return false;
+        std::vector<GLuint> aTextureIDs = pGlobalGlyphCache->maPackedTextureAtlas.ReduceTextureNumber(8);
+        if (!aTextureIDs.empty())
+        {
+            for (auto& pGlyphCache: pGlobalGlyphCache->maGlyphCaches)
+            {
+                pGlyphCache->RemoveTextures(aTextureIDs);
+            }
+        }
+        return true;
+    }
+
+    void RemoveTextures(std::vector<GLuint>& rTextureIDs)
+    {
+        auto it = maOpenGLTextureCache.begin();
+
+        while (it != maOpenGLTextureCache.end())
+        {
+            GLuint nTextureID = it->second.maTexture.Id();
+
+            if (std::find(rTextureIDs.begin(), rTextureIDs.end(), nTextureID) != rTextureIDs.end())
+            {
+                it = maOpenGLTextureCache.erase(it);
+            }
+            else
+            {
+                ++it;
+            }
+        }
+    }
+
+    void PutDrawElementInCache(const OpenGLGlyphDrawElement& rElement, int nGlyphIndex)
+    {
+        assert(!IsGlyphCached(nGlyphIndex));
+        maOpenGLTextureCache[nGlyphIndex] = OpenGLGlyphDrawElement(rElement);
+    }
+
+    OpenGLGlyphDrawElement& GetDrawElement(int nGlyphIndex)
+    {
+        assert(IsGlyphCached(nGlyphIndex));
+        return maOpenGLTextureCache[nGlyphIndex];
+    }
+
+    bool IsGlyphCached(int nGlyphIndex) const
+    {
+        return maOpenGLTextureCache.find(nGlyphIndex) != maOpenGLTextureCache.end();
+    }
+};
+
+// win32 specific physical font instance
+class WinFontInstance : public LogicalFontInstance
+{
+public:
+    explicit                WinFontInstance( FontSelectPattern& );
+    virtual                 ~WinFontInstance();
+    void                    setupGLyphy(HDC hDC);
+
+private:
+    // TODO: also add HFONT??? Watch out for issues with too many active fonts...
+
+public:
+    bool                    HasKernData() const;
+    void                    SetKernData( int, const KERNINGPAIR* );
+    int                     GetKerning( sal_Unicode, sal_Unicode ) const;
+
+private:
+    KERNINGPAIR*            mpKerningPairs;
+    int                     mnKerningPairs;
+
+public:
+    SCRIPT_CACHE&           GetScriptCache() const
+                            { return maScriptCache; }
+private:
+    mutable SCRIPT_CACHE    maScriptCache;
+
+public:
+    int                     GetCachedGlyphWidth( int nCharCode ) const;
+    void                    CacheGlyphWidth( int nCharCode, int nCharWidth );
+
+    bool                    InitKashidaHandling( HDC );
+    int                     GetMinKashidaWidth() const { return mnMinKashidaWidth; }
+    int                     GetMinKashidaGlyph() const { return mnMinKashidaGlyph; }
+
+    static GLuint             mnGLyphyProgram;
+    demo_atlas_t*             mpGLyphyAtlas;
+    demo_font_t*              mpGLyphyFont;
+
+private:
+    GlyphCache maGlyphCache;
+public:
+    bool CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex, const WinLayout& rLayout, SalGraphics& rGraphics);
+
+    GlyphCache& GetGlyphCache()
+    {
+        return maGlyphCache;
+    }
+
+private:
+    IntMap                  maWidthMap;
+    mutable int             mnMinKashidaWidth;
+    mutable int             mnMinKashidaGlyph;
+    bool                    mbGLyphySetupCalled;
+};
+
 class WinLayout : public SalLayout
 {
 public:
@@ -185,7 +365,6 @@ private:
 };
 
 #if ENABLE_GRAPHITE
-
 class GraphiteLayoutWinImpl : public GraphiteLayout
 {
 public:
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 954187d..4e0c0eb 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -26,7 +26,6 @@
 
 #include <opengl/texture.hxx>
 #include <opengl/win/gdiimpl.hxx>
-#include "opengl/PackedTextureAtlas.hxx"
 
 #include <vcl/opengl/OpenGLHelper.hxx>
 #include <win/salgdi.h>
@@ -50,195 +49,10 @@
 #include <unordered_map>
 #include <unordered_set>
 
-typedef std::unordered_map<int,int> IntMap;
-
-// Graphite headers
-#include <config_graphite.h>
-#if ENABLE_GRAPHITE
-#include <i18nlangtag/languagetag.hxx>
-#include <graphite_features.hxx>
-#if ENABLE_GRAPHITE_DWRITE
-#include <d2d1.h>
-#include <dwrite.h>
-#endif
-#endif
-
-// This needs to come after any includes for d2d1.h, otherwise we get lots of errors
-#include "glyphy/demo.hxx"
-
-
 #define DROPPED_OUTGLYPH 0xFFFF
 
-namespace
-{
-// Extra space at the top and bottom of the glyph in total = tmHeight / GLYPH_SPACE_RATIO;
-const int GLYPH_SPACE_RATIO = 8;
-// Border size at the top of the glyph = tmHeight / GLYPH_OFFSET_RATIO;
-const int GLYPH_OFFSET_RATIO = GLYPH_SPACE_RATIO * 2;
-}
-
-struct OpenGLGlyphDrawElement
-{
-    Rectangle maLocation;
-    int maLeftOverhangs;
-    OpenGLTexture maTexture;
-    int mnBaselineOffset;
-    int mnHeight;
-    bool mbVertical;
-    bool mbRealGlyphIndices;
-
-    int getExtraSpace() const
-    {
-        return std::max(mnHeight / GLYPH_SPACE_RATIO, 4);
-    }
-
-    int getExtraOffset() const
-    {
-        return std::max(mnHeight / GLYPH_OFFSET_RATIO, 2);
-    }
-};
-
-class GlyphCache;
-
-struct GlobalGlyphCache
-{
-    GlobalGlyphCache()
-        : maPackedTextureAtlas(2048, 2048)
-    {}
-
-    PackedTextureAtlasManager maPackedTextureAtlas;
-    std::unordered_set<GlyphCache*> maGlyphCaches;
-};
-
-class GlyphCache
-{
-private:
-    static std::unique_ptr<GlobalGlyphCache> gGlobalGlyphCache;
-    std::unordered_map<int, OpenGLGlyphDrawElement> maOpenGLTextureCache;
-
-public:
-    GlyphCache()
-    {
-        gGlobalGlyphCache.get()->maGlyphCaches.insert(this);
-    }
-
-    ~GlyphCache()
-    {
-        gGlobalGlyphCache.get()->maGlyphCaches.erase(this);
-    }
-
-    bool ReserveTextureSpace(OpenGLGlyphDrawElement& rElement, int nWidth, int nHeight)
-    {
-        GlobalGlyphCache* pGlobalGlyphCache = gGlobalGlyphCache.get();
-        rElement.maTexture = pGlobalGlyphCache->maPackedTextureAtlas.Reserve(nWidth, nHeight);
-        if (!rElement.maTexture)
-            return false;
-        std::vector<GLuint> aTextureIDs = pGlobalGlyphCache->maPackedTextureAtlas.ReduceTextureNumber(8);
-        if (!aTextureIDs.empty())
-        {
-            for (auto& pGlyphCache: pGlobalGlyphCache->maGlyphCaches)
-            {
-                pGlyphCache->RemoveTextures(aTextureIDs);
-            }
-        }
-        return true;
-    }
-
-    void RemoveTextures(std::vector<GLuint>& rTextureIDs)
-    {
-        auto it = maOpenGLTextureCache.begin();
-
-        while (it != maOpenGLTextureCache.end())
-        {
-            GLuint nTextureID = it->second.maTexture.Id();
-
-            if (std::find(rTextureIDs.begin(), rTextureIDs.end(), nTextureID) != rTextureIDs.end())
-            {
-                it = maOpenGLTextureCache.erase(it);
-            }
-            else
-            {
-                ++it;
-            }
-        }
-    }
-
-    void PutDrawElementInCache(const OpenGLGlyphDrawElement& rElement, int nGlyphIndex)
-    {
-        assert(!IsGlyphCached(nGlyphIndex));
-        maOpenGLTextureCache[nGlyphIndex] = OpenGLGlyphDrawElement(rElement);
-    }
-
-    OpenGLGlyphDrawElement& GetDrawElement(int nGlyphIndex)
-    {
-        assert(IsGlyphCached(nGlyphIndex));
-        return maOpenGLTextureCache[nGlyphIndex];
-    }
-
-    bool IsGlyphCached(int nGlyphIndex) const
-    {
-        return maOpenGLTextureCache.find(nGlyphIndex) != maOpenGLTextureCache.end();
-    }
-};
-
 // static initialization
 std::unique_ptr<GlobalGlyphCache> GlyphCache::gGlobalGlyphCache(new GlobalGlyphCache);
-
-// win32 specific physical font instance
-class WinFontInstance : public LogicalFontInstance
-{
-public:
-    explicit                WinFontInstance( FontSelectPattern& );
-    virtual                 ~WinFontInstance();
-    void                    setupGLyphy(HDC hDC);
-
-private:
-    // TODO: also add HFONT??? Watch out for issues with too many active fonts...
-
-public:
-    bool                    HasKernData() const;
-    void                    SetKernData( int, const KERNINGPAIR* );
-    int                     GetKerning( sal_Unicode, sal_Unicode ) const;
-
-private:
-    KERNINGPAIR*            mpKerningPairs;
-    int                     mnKerningPairs;
-
-public:
-    SCRIPT_CACHE&           GetScriptCache() const
-                            { return maScriptCache; }
-private:
-    mutable SCRIPT_CACHE    maScriptCache;
-
-public:
-    int                     GetCachedGlyphWidth( int nCharCode ) const;
-    void                    CacheGlyphWidth( int nCharCode, int nCharWidth );
-
-    bool                    InitKashidaHandling( HDC );
-    int                     GetMinKashidaWidth() const { return mnMinKashidaWidth; }
-    int                     GetMinKashidaGlyph() const { return mnMinKashidaGlyph; }
-
-    static GLuint             mnGLyphyProgram;
-    demo_atlas_t*             mpGLyphyAtlas;
-    demo_font_t*              mpGLyphyFont;
-
-private:
-    GlyphCache maGlyphCache;
-public:
-    bool CacheGlyphToAtlas(bool bRealGlyphIndices, int nGlyphIndex, const WinLayout& rLayout, SalGraphics& rGraphics);
-
-    GlyphCache& GetGlyphCache()
-    {
-        return maGlyphCache;
-    }
-
-private:
-    IntMap                  maWidthMap;
-    mutable int             mnMinKashidaWidth;
-    mutable int             mnMinKashidaGlyph;
-    bool                    mbGLyphySetupCalled;
-};
-
 GLuint WinFontInstance::mnGLyphyProgram = 0;
 
 class TextOutRenderer
commit b66e0bbfd4db16ac243c66bd4eb9112cbe6eb827
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 13:37:18 2016 +0530

    GSoC: Move winlayout header file to vcl/inc/win
    
    The winlayout header file will need to be included in the new layout
    class. Its better to move it to vcl/inc.
    
    Change-Id: Ifb4170e1948dc56b5ec1728380eff7c2b4a07137

diff --git a/vcl/win/gdi/winlayout.hxx b/vcl/inc/win/winlayout.hxx
similarity index 100%
rename from vcl/win/gdi/winlayout.hxx
rename to vcl/inc/win/winlayout.hxx
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index 7133a7c..954187d 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -17,7 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "winlayout.hxx"
+#include "win/winlayout.hxx"
 
 #include "osl/module.h"
 #include "osl/file.h"
commit 79d6a15eb45078d3069c198d7adf33ecdd13f07d
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 13:12:12 2016 +0530

    GSoC: Move scrptrun header and source file out of unx
    
    Scrptrun class will be used by the new layout engine for script
    itemisation. It will need to be compiled on all platforms. Therefore
    move the header and source file to vcl/inc/ and vcl/source/gdi/
    respectively.
    
    Change-Id: If4e1e0e76ffb94f9d0ca08f7d5f9982dd907c1c6

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 83383ff..a43402b 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -544,7 +544,6 @@ vcl_headless_freetype_code=\
     vcl/unx/generic/glyphs/freetype_glyphcache \
     vcl/unx/generic/glyphs/gcach_layout \
     vcl/unx/generic/glyphs/glyphcache \
-    vcl/unx/generic/glyphs/scrptrun \
     vcl/unx/generic/fontmanager/fontsubst \
     vcl/unx/generic/fontmanager/fontcache \
     vcl/unx/generic/fontmanager/fontconfig \
diff --git a/vcl/unx/generic/glyphs/scrptrun.h b/vcl/inc/scrptrun.h
old mode 100644
new mode 100755
similarity index 100%
rename from vcl/unx/generic/glyphs/scrptrun.h
rename to vcl/inc/scrptrun.h
diff --git a/vcl/unx/generic/glyphs/scrptrun.cxx b/vcl/source/gdi/scrptrun.cxx
old mode 100644
new mode 100755
similarity index 100%
rename from vcl/unx/generic/glyphs/scrptrun.cxx
rename to vcl/source/gdi/scrptrun.cxx
commit 2eb2027c5537f36b9ce4d3f28b040b2f2abc389d
Author: Akash Jain <akash96j at gmail.com>
Date:   Tue Jun 14 13:07:20 2016 +0530

    GSoC: Add a generic GetTable function for WinFontFace
    
    Change-Id: Ia10ffd8c4b5e0cef89571204f5f1df32daa9edb7

diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index d2a8162..b6e8cce 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -142,6 +142,7 @@ private:
 public:
     bool                    HasGSUBstitutions( HDC ) const;
     bool                    IsGSUBstituted( sal_UCS4 ) const;
+    int                     GetTable( const char pTagName[5], const unsigned char*&, HDC ) const;
 };
 
 /** Class that creates (and destroys) a compatible Device Context.
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index ba92247..4c8865e 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -1057,7 +1057,7 @@ sal_IntPtr WinFontFace::GetFontId() const
 }
 
 static unsigned GetUInt( const unsigned char* p ) { return((p[0]<<24)+(p[1]<<16)+(p[2]<<8)+p[3]);}
-static inline DWORD CalcTag( const char p[4]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
+static inline DWORD CalcTag( const char p[5]) { return (p[0]+(p[1]<<8)+(p[2]<<16)+(p[3]<<24)); }
 
 void WinFontFace::UpdateFromHDC( HDC hDC ) const
 {
@@ -1203,6 +1203,18 @@ void WinFontFace::ReadCmapTable( HDC hDC ) const
     }
 }
 
+int WinFontFace::GetTable(const char pTagName[5], const unsigned char*& pResBuffer, HDC hDC) const
+{
+    const DWORD nTableTag = CalcTag( pTagName );
+    RawFontData aRawFontData( hDC, nTableTag );
+
+    if( !aRawFontData.get() )
+        return 0;
+
+    pResBuffer = aRawFontData.steal();
+    return aRawFontData.size();
+}
+
 void WinFontFace::GetFontCapabilities( HDC hDC ) const
 {
     // read this only once per font


More information about the Libreoffice-commits mailing list