r15590 by pierremarc - Harbuzz was not considering LangSysDefault (dflt) as a special case,

scribus-commit scribus-commit at lists.scribus.net
Wed Oct 20 11:36:19 CEST 2010


Author: pierremarc
Date: Wed Oct 20 09:36:19 2010
New Revision: 15590

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15590
Log:
Harbuzz was not  considering LangSysDefault (dflt) as a special case,
thus making impossible to properly enumerate OpenType features.

Modified:
    branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
    branches/ScribusOIF/scribus/fonts/schbfunctions.h
    branches/ScribusOIF/scribus/text/legacylayout.cpp
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc

Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15590&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.cpp (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.cpp Wed Oct 20 09:36:19 2010
@@ -454,35 +454,41 @@
 	hb_face_t * face = hb_ft_face_create(ftface, releaseFaceForHB );
 	QList<hb_tag_t> tables;
 	tables << HB_TAG('G','P','O','S') << HB_TAG('G','S','U','B');
+	unsigned int script_index = 0;
+	unsigned int language_index = 0;
 	foreach(hb_tag_t table, tables)
 	{
 		unsigned int script_count = hb_ot_layout_table_get_script_count(face, table);
-		bool hastDFLTScript(hb_ot_layout_table_find_script(face,table,HB_OT_TAG_DEFAULT_SCRIPT, 0));
+		bool hastDFLTScript(hb_ot_layout_table_find_script(face,table,HB_OT_TAG_DEFAULT_SCRIPT, &script_index));
 		hb_tag_t     * script_tags = new hb_tag_t[(hastDFLTScript ? script_count + 1 : script_count)];
 		if(hastDFLTScript)
 			script_tags[0] = HB_OT_TAG_DEFAULT_SCRIPT;
+		else
+			qDebug()<<"No default script for"<< tagToString(table) <<ftface->family_name<<ftface->style_name ;
 		hb_ot_layout_table_get_script_tags (face, table, 0, &script_count, (hastDFLTScript ? script_tags + 1 :  script_tags));
 		qDebug()<<"Table:"<<tagToString(table)<<"ScriptCount:"<<script_count;
 
 		for(unsigned int scIdx(0); scIdx < script_count; ++scIdx)
 		{
-			unsigned int script_index = 0;
+			script_index = 0;
 			hb_ot_layout_table_find_script (face, table, script_tags[scIdx], &script_index);
 			unsigned int language_count = hb_ot_layout_script_get_language_count(face, table, script_index);
-			bool hasDFLTLang(hb_ot_layout_script_find_language(face, table,script_index, HB_OT_TAG_DEFAULT_LANGUAGE, 0));
-			hb_tag_t      * language_tags =  new hb_tag_t[(hasDFLTLang ? language_count + 1: language_count)];
+			bool hasDFLTLang(hb_ot_layout_script_find_language(face, table, script_index, HB_OT_TAG_DEFAULT_LANGUAGE, &language_index));
+			hb_tag_t * language_tags =  new hb_tag_t[(hasDFLTLang ? language_count + 1: language_count)];
 			if(hasDFLTLang)
 				language_tags[0] =  HB_OT_TAG_DEFAULT_LANGUAGE;
+			else
+				qDebug()<<"No default lang for"<< tagToString(table) <<tagToString(script_tags[scIdx]) <<ftface->family_name<<ftface->style_name ;
 			hb_ot_layout_script_get_language_tags(face, table, script_index, 0, &language_count , (hasDFLTLang ? language_tags + 1 : language_tags) );
 			qDebug()<<"\tScript:"<<tagToString(script_tags[scIdx])<<"LanguageCount:"<<language_count;
 
 			for(unsigned int laIdx(0); laIdx < language_count; ++laIdx)
 			{
-				unsigned int language_index = 0;
+				language_index = 0;
 				hb_ot_layout_script_find_language (face, table,  script_index, language_tags[laIdx], &language_index);
 				unsigned int feature_count = hb_ot_layout_language_get_feature_count(face, table, script_index, language_index);
 				hb_tag_t * feature_tags = new hb_tag_t[feature_count];
-				hb_ot_layout_language_get_feature_tags (face, table, scIdx, laIdx, 0, &feature_count, feature_tags );
+				hb_ot_layout_language_get_feature_tags (face, table, script_index, language_index , 0, &feature_count, feature_tags );
 				qDebug()<<"\t\tLanguage:"<<tagToString(language_tags[laIdx])<<"FeatureCount:"<<feature_count;
 
 				for(unsigned int feIdx(0); feIdx < feature_count; ++feIdx)
@@ -733,6 +739,7 @@
 int ScFace_ttf::shapeText(GlyphStore* gs) const
 {
 	hb_face_t * face = hb_ft_face_create(ftFace(), releaseFaceForHB );
+	hb_font_t * font = hb_ft_font_create (ftFace(), releaseFaceForHB);
 	// we'll make a first try with required features liga & kern
 	unsigned int itemCount(gs->nrOfItems());
 	const TextStore * story(gs->story());
@@ -751,10 +758,9 @@
 		foreach(unsigned int lookupIdx, gli)
 			hb_ot_layout_substitute_lookup(face, buf, lookupIdx, 0);
 
-//	We must wait to get something to build an hb_font, HB will drive me mad
-//		QList<unsigned int> pli(getlookupIndex("GPOS", "English", "kern"));
-//		foreach(unsigned int lookupIdx, pli)
-//			hb_ot_layout_position_lookup(face, buf, lookupIdx, 0);
+		QList<unsigned int> pli(getlookupIndex("GPOS", "English", "kern"));
+		foreach(unsigned int lookupIdx, pli)
+			hb_ot_layout_position_lookup(font, face, buf, lookupIdx, 0);
 
 		hb_ot_layout_position_finish(0,0,buf);
 
@@ -775,6 +781,9 @@
 			curGlyph->glyph = gi.codepoint;
 
 			gs->markCluster(it, gi.cluster, curGlyph);
+
+			qDebug()<<"ScFace_ttf::shapeText:"<<curGlyph->glyph<<curGlyph->xadvance<<curGlyph->xoffset;
+
 			++curGlyph;
 		}
 

Modified: branches/ScribusOIF/scribus/fonts/schbfunctions.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15590&path=/branches/ScribusOIF/scribus/fonts/schbfunctions.h
==============================================================================
--- branches/ScribusOIF/scribus/fonts/schbfunctions.h (original)
+++ branches/ScribusOIF/scribus/fonts/schbfunctions.h Wed Oct 20 09:36:19 2010
@@ -29,6 +29,14 @@
 #include "third_party/harfbuzz/src/hb-unicode.h"
 #include "third_party/harfbuzz/src/hb-buffer.h"
 
+class ScFace_ttf;
+
+/**
+  Harfbuzz library expects the client to provide a bunch of functions
+  in order to perform some of its operations. While it now provides
+  some of them as optional packages, it's at the price of GLib dependency.
+  */
+
 class ScHBFunctions
 {
 	static ScHBFunctions * instance;
@@ -48,7 +56,6 @@
 public:
 
 	static void setBufferFunctions(hb_buffer_t * buf);
-//	static void setFontFunctions(hb_buffer_t * buf){}
 };
 
 #endif // SCHBFUNCTIONS_H

Modified: branches/ScribusOIF/scribus/text/legacylayout.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15590&path=/branches/ScribusOIF/scribus/text/legacylayout.cpp
==============================================================================
--- branches/ScribusOIF/scribus/text/legacylayout.cpp (original)
+++ branches/ScribusOIF/scribus/text/legacylayout.cpp Wed Oct 20 09:36:19 2010
@@ -138,6 +138,7 @@
 	if(style.font().type() == ScFace::OTF)
 	{
 		shapeShape(typographicSettings, style, chars, textFlags, start, end, glyphs);
+		return;
 	}
 	double asce = style.font().ascent(style.fontSize() / 10.0);
 	int chst = style.effects() & 1919;

Modified: branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15590&path=/branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc
==============================================================================
--- branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc (original)
+++ branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc Wed Oct 20 09:36:19 2010
@@ -360,6 +360,8 @@
 {
      const GSUBGPOS &g = get_gsubgpos_table(face, table_tag);
      const Script &s = g.get_script(script_index);
+     if(s.has_default_lang_sys())
+	     return s.get_lang_sys_count() + 1;
      return s.get_lang_sys_count();
 }
 
@@ -371,7 +373,7 @@
 {
     const GSUBGPOS &g = get_gsubgpos_table(face, table_tag);
     const Script &s = g.get_script(script_index);
-    const LangSys &l = s.get_lang_sys(language_index);
+    const LangSys &l = (HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX == language_index) ? s.get_default_lang_sys() : s.get_lang_sys(language_index);
     return l.get_feature_count();
 }
 
@@ -463,7 +465,10 @@
 {
   const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
 
-  return s.get_lang_sys_tags (start_offset, language_count, language_tags);
+  unsigned int ret = s.get_lang_sys_tags (start_offset, language_count, language_tags);
+  if(s.has_default_lang_sys())
+	  *language_count += 1;
+  return ret;
 }
 
 hb_bool_t
@@ -475,6 +480,21 @@
 {
   ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX);
   const Script &s = get_gsubgpos_table (face, table_tag).get_script (script_index);
+
+  /*
+	from http://www.microsoft.com/typography/otspec/chapter2.htm
+	"...In addition, an array of Language System Records (LangSysRecord)
+	defines each language system (excluding the default) with an identification tag..."
+	As long as DefaultLangSys might be NULL, we need to enumerate
+	it as well as the client can't rely on its presence.
+ */
+  if((HB_OT_TAG_DEFAULT_LANGUAGE == language_tag)
+	  && (s.has_default_lang_sys()))
+  {
+	  if (language_index)
+		*language_index = HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX;
+	  return TRUE;
+  }
 
   if (s.find_lang_sys_index (language_tag, language_index))
     return TRUE;
@@ -526,7 +546,8 @@
 					hb_tag_t     *feature_tags /* OUT */)
 {
   const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
-  const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
+  const Script &s = g.get_script(script_index);
+  const LangSys &l = (HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX == language_index) ? s.get_default_lang_sys() : s.get_lang_sys(language_index);
 
   ASSERT_STATIC (sizeof (unsigned int) == sizeof (hb_tag_t));
   unsigned int ret = l.get_feature_indexes (start_offset, feature_count, (unsigned int *) feature_tags);
@@ -551,7 +572,8 @@
 {
   ASSERT_STATIC (Index::NOT_FOUND_INDEX == HB_OT_LAYOUT_NO_FEATURE_INDEX);
   const GSUBGPOS &g = get_gsubgpos_table (face, table_tag);
-  const LangSys &l = g.get_script (script_index).get_lang_sys (language_index);
+  const Script &s = g.get_script(script_index);
+  const LangSys &l = (HB_OT_LAYOUT_DEFAULT_LANGUAGE_INDEX == language_index) ? s.get_default_lang_sys() : s.get_lang_sys(language_index);
 
   unsigned int num_features = l.get_feature_count ();
   for (unsigned int i = 0; i < num_features; i++) {




More information about the scribus-commit mailing list