[Libreoffice-commits] core.git: 2 commits - vcl/source
Khaled Hosny
khaledhosny at eglug.org
Thu Oct 20 14:56:21 UTC 2016
vcl/source/gdi/CommonSalLayout.cxx | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
New commits:
commit d5424208a5b63a9d5ac658279c3f9824aa38a2d6
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Thu Oct 20 16:37:22 2016 +0200
Reuse the HarfBuzz buffer as much as possible
Less allocations in case we have many sub runs.
Change-Id: I50d4a57702c030c185fc7edef576c64d739a6194
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index b8f18c4..cdb9b19 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -418,6 +418,13 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
pTextLayout = pNewScriptRun.get();
}
+ hb_buffer_t* pHbBuffer = hb_buffer_create();
+ hb_buffer_pre_allocate(pHbBuffer, nGlyphCapacity);
+#if !HB_VERSION_ATLEAST(1, 1, 0)
+ static hb_unicode_funcs_t* pHbUnicodeFuncs = getUnicodeFuncs();
+ hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs);
+#endif
+
Point aCurrPos(0, 0);
while (true)
{
@@ -457,6 +464,8 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
for (const auto& aScriptRun : aScriptSubRuns)
{
+ hb_buffer_clear_contents(pHbBuffer);
+
int nMinRunPos = aScriptRun.mnMin;
int nEndRunPos = aScriptRun.mnEnd;
int nRunLen = nEndRunPos - nMinRunPos;
@@ -479,11 +488,6 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
if (nEndRunPos == nLength)
nHbFlags |= HB_BUFFER_FLAG_EOT; /* End-of-text */
- hb_buffer_t *pHbBuffer = hb_buffer_create();
-#if !HB_VERSION_ATLEAST(1, 1, 0)
- static hb_unicode_funcs_t* pHbUnicodeFuncs = getUnicodeFuncs();
- hb_buffer_set_unicode_funcs(pHbBuffer, pHbUnicodeFuncs);
-#endif
if (bVertical)
hb_buffer_set_direction(pHbBuffer, HB_DIRECTION_TTB);
else
@@ -592,11 +596,11 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
aCurrPos.X() += nAdvance;
}
-
- hb_buffer_destroy(pHbBuffer);
}
}
+ hb_buffer_destroy(pHbBuffer);
+
// sort glyphs in visual order
// and then in logical order (e.g. diacritics after cluster start)
// XXX: why?
commit 7854d35cd8172b201f1f3ad247860f242e5cb06b
Author: Khaled Hosny <khaledhosny at eglug.org>
Date: Thu Oct 6 04:15:41 2016 +0200
Use HarfBuzz shape plan for a bit more control
This way we control exactly what shapers we use in what order, and as an
extra we can now tell which shaper HarfBuzz ends up using.
Change-Id: Idd303b2a557e16ac86ada0c2006d3e2a052ac489
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 527d827..b8f18c4 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -397,6 +397,7 @@ static int GetVerticalFlagsForScript(UScriptCode aScript)
bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
{
+ hb_face_t* pHbFace = hb_font_get_face(mpHbFont);
hb_script_t aHbScript = HB_SCRIPT_INVALID;
int nGlyphCapacity = 2 * (rArgs.mnEndCharPos - rArgs.mnMinCharPos);
@@ -496,7 +497,18 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
#if HB_VERSION_ATLEAST(0, 9, 42)
hb_buffer_set_cluster_level(pHbBuffer, HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS);
#endif
- hb_shape(mpHbFont, pHbBuffer, maFeatures.data(), maFeatures.size());
+ // The shapers that we want HarfBuzz to use, in the order of
+ // preference. The coretext_aat shaper is available only on macOS,
+ // but there is no harm in always including it, HarfBuzz will
+ // ignore unavailable shapers.
+ const char* pHbShapers[] = { "coretext_aat", "graphite2", "ot", "fallback", nullptr };
+ hb_segment_properties_t aHbProps;
+ hb_buffer_get_segment_properties(pHbBuffer, &aHbProps);
+ hb_shape_plan_t* pHbPlan = hb_shape_plan_create_cached(pHbFace, &aHbProps, maFeatures.data(), maFeatures.size(), pHbShapers);
+ bool ok = hb_shape_plan_execute(pHbPlan, mpHbFont, pHbBuffer, maFeatures.data(), maFeatures.size());
+ assert(ok);
+ (void) ok;
+ SAL_INFO("vcl.harfbuzz", hb_shape_plan_get_shaper(pHbPlan) << " shaper used for " << mrFontSelData.GetFamilyName());
int nRunGlyphCount = hb_buffer_get_length(pHbBuffer);
hb_glyph_info_t *pHbGlyphInfos = hb_buffer_get_glyph_infos(pHbBuffer, nullptr);
@@ -529,7 +541,6 @@ bool CommonSalLayout::LayoutText(ImplLayoutArgs& rArgs)
nGlyphFlags |= GlyphItem::IS_IN_CLUSTER;
bool bDiacritic = false;
- hb_face_t* pHbFace = hb_font_get_face(mpHbFont);
if (hb_ot_layout_has_glyph_classes(pHbFace))
{
// the font has GDEF table
More information about the Libreoffice-commits
mailing list