r15609 by pierremarc - First visible result of applying OpenType features to a run of text through the new text engine

scribus-commit scribus-commit at lists.scribus.net
Thu Oct 21 15:49:49 CEST 2010


Author: pierremarc
Date: Thu Oct 21 13:49:49 2010
New Revision: 15609

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15609
Log:
First visible result of applying OpenType features to a run of text through the new text engine

Modified:
    branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
    branches/ScribusOIF/scribus/fonts/scface_ttf.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc

Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15609&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.cpp (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.cpp Thu Oct 21 13:49:49 2010
@@ -45,8 +45,6 @@
     return HB_TAG(tag.at(0).toAscii(),tag.at(1).toAscii(),tag.at(2).toAscii(),tag.at(3).toAscii());
 }
 
-// TODO move it to a better place
-QMap<QString, QPair<hb_tag_t, hb_tag_t> > scLangToTags;
 
 KernFeature::KernFeature ( FT_Face face )
 	:m_valid ( true )
@@ -524,6 +522,9 @@
 	return ret;
 }
 
+// TODO move it to a better place
+QMap<QString, QPair<hb_tag_t, hb_tag_t> > ScFace_ttf::scLangToTags;
+
 ScFace_ttf::ScFace_ttf ( QString fam, QString sty, QString alt, QString scname, QString psname, QString path, int face )
 	: FtFace ( fam, sty, alt, scname, psname, path, face )
 {
@@ -746,23 +747,47 @@
 	for(unsigned int it(0); it < itemCount; ++it)
 	{
 		hb_buffer_t * buf = hb_buffer_create(gs->itemCharCount(it));
+		hb_buffer_clear(buf);
+		hb_buffer_clear_positions(buf);
 		ScHBFunctions::setBufferFunctions(buf);
+		hb_buffer_set_direction(buf, HB_DIRECTION_LTR);
 		unsigned int end(gs->itemTextPosition(it) + gs->itemCharCount(it));
+		QString language(story->charStyle(gs->itemTextPosition(it)).language());
+		double fSize(story->charStyle(gs->itemTextPosition(it)).fontSize() /10.0);
+		hb_font_set_scale(font, fSize * 1000, fSize * 1000);
+		unsigned int counterP(0);
 		for(unsigned int ci(gs->itemTextPosition(it)); ci < end; ++ci)
 		{
 			unsigned int gIndex(char2CMap(story->text(ci,1).at(0)));
 			hb_buffer_add_glyph(buf, gIndex, 0x1, ci);
-		}
-
-		QList<unsigned int> gli(getlookupIndex("GSUB", "English", "liga"));
+			hb_glyph_position_t * pos = hb_buffer_get_glyph_positions(buf) + counterP;
+			pos->x_advance = 0;
+			pos->x_offset = 0;
+			pos->y_advance = 0;
+			pos->y_offset = 0;
+			++counterP;
+		}
+
+		// DEBUGGING
+		hb_position_t  Txadv = (hb_buffer_get_glyph_positions(buf)->x_offset);
+		hb_position_t  oxadv = ((hb_buffer_get_glyph_positions(buf) + 1)->x_offset);
+		// EOD
+
+		QList<unsigned int> gli(getlookupIndex("GSUB", language , "liga"));
 		foreach(unsigned int lookupIdx, gli)
-			hb_ot_layout_substitute_lookup(face, buf, lookupIdx, 0);
-
-		QList<unsigned int> pli(getlookupIndex("GPOS", "English", "kern"));
+		{
+			if(!hb_ot_layout_substitute_lookup(face, buf, lookupIdx, 0x1))
+				qDebug()<<"Failed to apply lookup"<< lookupIdx<< "[liga] to"<<family<<style;
+		}
+
+		QList<unsigned int> pli(getlookupIndex("GPOS", language, "kern"));
 		foreach(unsigned int lookupIdx, pli)
-			hb_ot_layout_position_lookup(font, face, buf, lookupIdx, 0);
-
-		hb_ot_layout_position_finish(0,0,buf);
+		{
+			if(!hb_ot_layout_position_lookup(font, face, buf, lookupIdx, 0x1))
+				qDebug()<<"Failed to apply lookup"<< lookupIdx<< "[kern] to"<<family<<style;
+		}
+
+//		hb_ot_layout_position_finish(font,face,buf);
 
 		unsigned int bLen(hb_buffer_get_length(buf));
 		hb_glyph_info_t * gInfos = hb_buffer_get_glyph_infos (buf);
@@ -774,7 +799,7 @@
 		{
 			hb_glyph_info_t  gi = gInfos[bIdx];
 			hb_glyph_position_t  gp = gPositions[bIdx];
-			curGlyph->xadvance = gp.x_advance;
+			curGlyph->xadvance = glyphWidth(gi.codepoint, fSize) + (double(gp.x_advance) / 1000.0);
 			curGlyph->xoffset = gp.x_offset;
 			curGlyph->yadvance = gp.y_advance;
 			curGlyph->yoffset = gp.y_offset;
@@ -782,7 +807,7 @@
 
 			gs->markCluster(it, gi.cluster, curGlyph);
 
-			qDebug()<<"ScFace_ttf::shapeText:"<<curGlyph->glyph<<curGlyph->xadvance<<curGlyph->xoffset;
+			qDebug()<<"ScFace_ttf::shapeText:" <<curGlyph->glyph <<glyphWidth(gi.codepoint, fSize) <<curGlyph->xadvance <<curGlyph->xoffset;
 
 			++curGlyph;
 		}
@@ -801,36 +826,44 @@
 	{
 		hb_tag_t scriptTag = scLangToTags[language].first;
 		hb_tag_t langTag = scLangToTags[language].second;
-		hb_tag_t featureTag = stringToTag(feature);
-		bool haveIt(false);
-		QList<FontFeatureSet::Feature> ff = featureSet->features(t == HB_OT_TAG_GSUB ? FontFeatureSet::Sub :FontFeatureSet::Pos );
-		foreach(const FontFeatureSet::Feature& f, ff)
-		{
-			if((f.name == feature)
-				&& (f.lang.contains( tagToString(langTag) )) )
-				{
-				haveIt = true;
-				break;
-			}
-		}
-		if(haveIt)
-		{
-			hb_face_t * face = hb_ft_face_create(ftFace(), releaseFaceForHB );
-			unsigned int scriptIndex(0);
-			unsigned int languageIndex(0);
-			unsigned int featureIndex(0);
-			unsigned int lookupIndex(0);
-			hb_ot_layout_table_find_script(face, t,scriptTag, &scriptIndex);
-			hb_ot_layout_script_find_language(face, t, scriptIndex, langTag, &languageIndex);
-			hb_ot_layout_language_find_feature(face, t,scriptIndex, languageIndex, featureTag, &featureIndex);
-			unsigned int lookupCount(hb_ot_layout_feature_get_lookup_indexes (face,t,  featureIndex,0, 0 ,0));
-			unsigned int * lookup_indexes = new unsigned int[lookupCount];
-			hb_ot_layout_feature_get_lookup_indexes (face,t,  featureIndex,0, &lookupCount, lookup_indexes);
-			QList<unsigned int> ret;
-			for(unsigned int ui(0); ui < lookupCount; ++ui)
-				ret << lookup_indexes[ui];
-			delete lookup_indexes;
-			return ret;
+		if(feature.isEmpty())
+		{
+
+		}
+		else
+		{
+			hb_tag_t featureTag = stringToTag(feature);
+			bool haveIt(false);
+			QList<FontFeatureSet::Feature> ff = featureSet->features(t == HB_OT_TAG_GSUB ? FontFeatureSet::Sub :FontFeatureSet::Pos );
+			foreach(const FontFeatureSet::Feature& f, ff)
+			{
+				if((f.name == feature)
+					/* FIXME_OIF && (f.lang.contains( tagToString(langTag) ))*/ )
+					{
+					haveIt = true;
+					break;
+				}
+			}
+			if(haveIt)
+			{
+				hb_face_t * face = hb_ft_face_create(ftFace(), releaseFaceForHB );
+				unsigned int scriptIndex(0);
+				unsigned int languageIndex(0);
+				unsigned int featureIndex(0);
+				unsigned int lookupIndex(0);
+				hb_ot_layout_table_find_script(face, t,scriptTag, &scriptIndex);
+				if(!hb_ot_layout_script_find_language(face, t, scriptIndex, langTag, &languageIndex))
+					hb_ot_layout_script_find_language(face, t, scriptIndex, HB_OT_TAG_DEFAULT_LANGUAGE, &languageIndex);
+				hb_ot_layout_language_find_feature(face, t,scriptIndex, languageIndex, featureTag, &featureIndex);
+				unsigned int lookupCount(hb_ot_layout_feature_get_lookup_indexes (face,t,  featureIndex,0, 0 ,0));
+				unsigned int * lookup_indexes = new unsigned int[lookupCount];
+				hb_ot_layout_feature_get_lookup_indexes (face,t,  featureIndex,0, &lookupCount, lookup_indexes);
+				QList<unsigned int> ret;
+				for(unsigned int ui(0); ui < lookupCount; ++ui)
+					ret << lookup_indexes[ui];
+				delete lookup_indexes;
+				return ret;
+			}
 		}
 	}
 	return QList<unsigned int>();

Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15609&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.h
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.h (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.h Thu Oct 21 13:49:49 2010
@@ -11,7 +11,10 @@
 #include "fonts/ftface.h"
 #include "fonts/fontfeatureset.h"
 
+#include "third_party/harfbuzz/src/hb.h"
+
 #include <QMap>
+#include <QPair>
 
 #include FT_TRUETYPE_TABLES_H
 #include FT_TRUETYPE_TAGS_H
@@ -111,6 +114,7 @@
 		int shapeText( GlyphStore* gs) const;
 
 	private:
+		static QMap<QString, QPair<hb_tag_t, hb_tag_t> > scLangToTags;
 		void fillLangToTag();
 		QList<unsigned int> getlookupIndex(const QString& table, const QString& language, const QString& feature) const;
 		mutable KernFeature * kernFeature;

Modified: branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15609&path=/branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc
==============================================================================
--- branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc (original)
+++ branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc Thu Oct 21 13:49:49 2010
@@ -520,8 +520,8 @@
 hb_glyph_position_t *
 hb_buffer_get_glyph_positions (hb_buffer_t *buffer)
 {
-  if (!buffer->have_positions)
-    hb_buffer_clear_positions (buffer);
+ /* if (!buffer->have_positions)
+    hb_buffer_clear_positions (buffer);*/
 
   return (hb_glyph_position_t *) buffer->pos;
 }




More information about the scribus-commit mailing list