r15532 by pierremarc - Added Harfbuzz library to third parties,

scribus-commit scribus-commit at lists.scribus.net
Wed Oct 13 16:05:38 CEST 2010


Author: pierremarc
Date: Wed Oct 13 14:05:38 2010
New Revision: 15532

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15532
Log:
Added Harfbuzz library to third parties,
first bits of opentype features enumeration in scface_ttf

Added:
    branches/ScribusOIF/scribus/fonts/fontfeatureset.cpp
    branches/ScribusOIF/scribus/fonts/fontfeatureset.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/CMakeLists.txt
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-blob-private.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-blob.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-blob.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-buffer.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-common.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-common.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-font-private.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-font.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-font.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ft.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ft.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-glib.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-glib.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-graphite.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-graphite.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-icu.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-icu.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-language.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-language.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-object-private.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-open-file-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-open-type-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-head-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-common-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-gdef-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-gpos-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-gsub-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-gsubgpos-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-layout.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-map-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-map.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-shape-complex-arabic.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-shape-complex-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-shape-private.hh
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-shape.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-shape.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-tag.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot-tag.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-ot.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-private.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-shape.cc
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-shape.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-unicode-private.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-unicode.c
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb-unicode.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hb.h
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hbotlayout_class.cpp
    branches/ScribusOIF/scribus/third_party/harfbuzz/src/hbotlayout_class.h
Modified:
    branches/ScribusOIF/scribus/CMakeLists.txt
    branches/ScribusOIF/scribus/fonts/CMakeLists.txt
    branches/ScribusOIF/scribus/fonts/scface.h
    branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
    branches/ScribusOIF/scribus/fonts/scface_ttf.h
    branches/ScribusOIF/scribus/third_party/CMakeLists.txt

Modified: branches/ScribusOIF/scribus/CMakeLists.txt
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&path=/branches/ScribusOIF/scribus/CMakeLists.txt
==============================================================================
--- branches/ScribusOIF/scribus/CMakeLists.txt (original)
+++ branches/ScribusOIF/scribus/CMakeLists.txt Wed Oct 13 14:05:38 2010
@@ -880,6 +880,7 @@
   SET(SCRIBUS_2GEOM_LIB "scribus_2geom_lib")
 ENDIF (HAVE_BOOST)
 SET(SCRIBUS_WPG_LIB "scribus_wpg_lib")
+SET(SCRIBUS_HARFBUZZ_LIB "scribus_harfbuzz_lib")
 
 INCLUDE_DIRECTORIES(
   ${CMAKE_SOURCE_DIR}
@@ -1041,6 +1042,7 @@
   ${SCRIBUS_STYLES_LIB}
   ${SCRIBUS_FONTS_LIB}
   ${SCRIBUS_WPG_LIB}
+  ${SCRIBUS_HARFBUZZ_LIB}
 )
 
 IF(HAVE_PODOFO)

Modified: branches/ScribusOIF/scribus/fonts/CMakeLists.txt
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&path=/branches/ScribusOIF/scribus/fonts/CMakeLists.txt
==============================================================================
--- branches/ScribusOIF/scribus/fonts/CMakeLists.txt (original)
+++ branches/ScribusOIF/scribus/fonts/CMakeLists.txt Wed Oct 13 14:05:38 2010
@@ -11,6 +11,7 @@
   scface_ps.cpp
   scface_ttf.cpp
   scfontmetrics.cpp
+fontfeatureset.cpp
 )
 SET(SCRIBUS_FONTS_LIB "scribus_fonts_lib")
 ADD_LIBRARY(${SCRIBUS_FONTS_LIB} STATIC ${SCRIBUS_FONTS_LIB_SOURCES})

Modified: branches/ScribusOIF/scribus/fonts/scface.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&path=/branches/ScribusOIF/scribus/fonts/scface.h
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface.h (original)
+++ branches/ScribusOIF/scribus/fonts/scface.h Wed Oct 13 14:05:38 2010
@@ -27,8 +27,7 @@
 #include <utility>
 
 #include "fpointarray.h"
-
-
+#include "fonts/fontfeatureset.h"
 
 struct GlyphMetrics {
 	qreal width;
@@ -181,6 +180,7 @@
 		virtual bool EmbedFont(QString &/*str*/)       const { return false; }
 		virtual void RawData(QByteArray & /*bb*/)      const {}
 		virtual bool glyphNames(QMap<uint, std::pair<QChar, QString> >& gList) const;
+		virtual FontFeatureSet * features() const { return 0; }
 
 		// these use the cache:
 		virtual qreal      glyphWidth(uint gl, qreal sz)   const;
@@ -373,6 +373,9 @@
 	
 	/// deprecated, see glyphBBox()
 	qreal realCharDescent(QChar ch, qreal sz=1.0) const { return glyphBBox(char2CMap(ch),sz).descent; }
+
+	/// Return a features Object provided by the font
+	FontFeatureSet * features() { return m->features();}
 	
 private:
 		

Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&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 13 14:05:38 2010
@@ -8,6 +8,7 @@
 #include <QFile>
 #include <QString>
 #include <QObject>
+#include <QByteArray>
 #include <QDebug>
 // #include <QTime>
 
@@ -15,20 +16,38 @@
 
 #include "fonts/scface_ttf.h"
 #include "fonts/scfontmetrics.h"
+#include "fonts/fontfeatureset.h"
 #include "util.h"
 #include "scconfig.h"
 
+
+#include "third_party/harfbuzz/src/hb-ot.h"
+#include "third_party/harfbuzz/src/hb-ft.h"
+
+// Missing feature in Harfbuzz
+QString tagToString(hb_tag_t tag)
+{
+    QString name;
+    name[0] = ( char ) ( tag >> 24 );
+    name[1] = ( char ) ( ( tag >> 16 ) & 0xFF );
+    name[2] = ( char ) ( ( tag >> 8 ) & 0xFF );
+    name[3] = ( char ) ( tag & 0xFF );
+    //   qDebug(QString("OTF_tag_name (%1) -> %2").arg(tag).arg(name));
+    return name;
+}
+
+
 KernFeature::KernFeature ( FT_Face face )
-		:m_valid ( true )
+	:m_valid ( true )
 {
 	FontName = QString ( face->family_name ) + " " + QString ( face->style_name )   ;
-// 	qDebug() <<"KF"<<FontName;
-// 	QTime t;
-// 	t.start();
+	// 	qDebug() <<"KF"<<FontName;
+	// 	QTime t;
+	// 	t.start();
 	FT_ULong length = 0;
 	if ( !FT_Load_Sfnt_Table ( face, TTAG_GPOS , 0, NULL, &length ) )
 	{
-// 		qDebug() <<"\t"<<"GPOS table len"<<length;
+		// 		qDebug() <<"\t"<<"GPOS table len"<<length;
 		if ( length > 32 )
 		{
 			GPOSTableRaw.resize ( length );
@@ -47,8 +66,8 @@
 
 	if ( !m_valid )
 		pairs.clear();
-// 	qDebug() <<"\t"<<m_valid;
-// 	qDebug() <<"\t"<<t.elapsed();
+	// 	qDebug() <<"\t"<<m_valid;
+	// 	qDebug() <<"\t"<<t.elapsed();
 }
 
 KernFeature::KernFeature ( const KernFeature & kf )
@@ -132,7 +151,7 @@
 		{
 			quint16 SubTable ( toUint16 ( Lookup + 6 + ( 2 * stIdx ) ) + Lookup );
 
-// 			quint16 PosFormat ( toUint16 ( SubTable ) );
+			// 			quint16 PosFormat ( toUint16 ( SubTable ) );
 			quint16 Coverage_Offset ( toUint16 ( SubTable + 2 ) + SubTable );
 			quint16 CoverageFormat ( toUint16 ( Coverage_Offset ) );
 
@@ -150,13 +169,13 @@
 			{
 				quint16 RangeCount ( toUint16 ( Coverage_Offset + 2 ) );
 
-// 				int gl_base ( 0 );
+				// 				int gl_base ( 0 );
 				for ( int r ( 0 ); r < RangeCount; ++r )
 				{
 					quint16 rBase ( Coverage_Offset + 4 + ( r * 6 ) );
 					quint16 Start ( toUint16 ( rBase ) );
 					quint16 End ( toUint16 ( rBase + 2 ) );
-// 					quint16 StartCoverageIndex ( toUint16 ( rBase + 4 ) );
+					// 					quint16 StartCoverageIndex ( toUint16 ( rBase + 4 ) );
 					for ( unsigned int gl ( Start ); gl <= End; ++gl )
 						coverages[SubTable]  << gl;
 				}
@@ -349,7 +368,7 @@
 	{
 		qDebug() << "HORROR!" << index << GPOSTableRaw.count() << FontName ;
 		// Rather no kerning at all than random kerning
-// 		m_valid = false;
+		// 		m_valid = false;
 		return 0;
 	}
 	// FIXME I just do not know how it has to be done *properly*
@@ -414,11 +433,80 @@
 	}
 } //namespace
 
+
+void releaseFaceForHB(void *){} // HB hassle
+
+TTFFeatureSet::TTFFeatureSet(FT_Face ftface)
+	:FontFeatureSet()
+{
+	// on prend son souffle :)
+	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');
+	foreach(hb_tag_t table, tables)
+	{
+		unsigned int script_count = hb_ot_layout_table_get_script_count(face, table);
+		hb_tag_t     * script_tags = new hb_tag_t[script_count];
+		hb_ot_layout_table_get_script_tags (face, table, 0, &script_count, script_tags);
+		qDebug()<<"Table:"<<tagToString(table)<<"ScriptCount:"<<script_count;
+
+		for(unsigned int scIdx(0); scIdx < script_count; ++scIdx)
+		{
+			unsigned int 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);
+			hb_tag_t      * language_tags =  new hb_tag_t[language_count];
+			hb_ot_layout_script_get_language_tags(face, table, script_index, 0, &language_count , 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;
+				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 );
+				qDebug()<<"\t\tLanguage:"<<tagToString(language_tags[laIdx])<<"FeatureCount:"<<feature_count;
+
+				for(unsigned int feIdx(0); feIdx < feature_count; ++feIdx)
+				{
+					QString feName(tagToString(feature_tags[feIdx]));
+					qDebug()<<"\t\t\tFeature:"<<feName;
+					FontFeatureSet::Feature& f = featuresList[feName];
+
+					f.name = feName;
+					f.type = (table == HB_TAG('G','P','O','S')) ? FontFeatureSet::Pos :  FontFeatureSet::Sub;
+					f.lang.append(tagToString(language_tags[laIdx]));
+					f.script.append(tagToString(script_tags[scIdx]));
+
+					qDebug()<<ftface->family_name<<ftface->style_name <<feName<< tagToString(script_tags[scIdx])<<tagToString(language_tags[laIdx])  ;
+				}
+				delete[] feature_tags;
+			}
+			delete[] language_tags;
+		}
+		delete[] script_tags;
+	}
+
+}
+
+QList<FontFeatureSet::Feature> TTFFeatureSet::features(FeatureType type) const
+{
+	QList<FontFeatureSet::Feature> ret;
+	foreach(FontFeatureSet::Feature f, featuresList.values())
+	{
+		if(f.type == type)
+			ret << f;
+	}
+	return ret;
+}
+
 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 )
+	: FtFace ( fam, sty, alt, scname, psname, path, face )
 {
 	formatCode = ScFace::SFNT;
 	kernFeature = 0;
+	featureSet = 0;
 }
 
 ScFace_ttf::~ ScFace_ttf()
@@ -430,15 +518,20 @@
 
 void ScFace_ttf::load() const
 {
+	FtFace::load();
 	if ( !kernFeature )
 		kernFeature = new KernFeature ( ftFace() );
-	FtFace::load();
+	if(!featureSet)
+		featureSet = new TTFFeatureSet( ftFace() );
 }
 
 void ScFace_ttf::unload() const
 {
 	if ( kernFeature )
 		delete kernFeature;
+	if(featureSet)
+		delete featureSet;
+	featureSet = 0;
 	kernFeature = 0;
 	FtFace::unload();
 }

Modified: branches/ScribusOIF/scribus/fonts/scface_ttf.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&path=/branches/ScribusOIF/scribus/fonts/scface_ttf.h
==============================================================================
--- branches/ScribusOIF/scribus/fonts/scface_ttf.h (original)
+++ branches/ScribusOIF/scribus/fonts/scface_ttf.h Wed Oct 13 14:05:38 2010
@@ -9,6 +9,9 @@
 
 #include "scribusapi.h"
 #include "fonts/ftface.h"
+#include "fonts/fontfeatureset.h"
+
+#include <QMap>
 
 #include FT_TRUETYPE_TABLES_H
 #include FT_TRUETYPE_TAGS_H
@@ -71,6 +74,15 @@
 		QString FontName;// for debugging purpose
 };
 
+class SCRIBUS_API TTFFeatureSet : public FontFeatureSet
+{
+	QMap<QString, Feature> featuresList;
+
+public:
+	TTFFeatureSet( FT_Face ftface );
+	QList<Feature> features(FeatureType type) const;
+
+};
 
 /*
 	Class ScFace_ttf
@@ -93,9 +105,12 @@
 		void RawData ( QByteArray & bb ) const;
 		
 		qreal glyphKerning ( uint gl1, uint gl2, qreal sz ) const;
+
+		TTFFeatureSet * features(FontFeatureSet::FeatureType type) const {return featureSet;}
 		
 	private:
 		mutable KernFeature * kernFeature;
+		mutable TTFFeatureSet * featureSet;
 };
 
 #endif

Modified: branches/ScribusOIF/scribus/third_party/CMakeLists.txt
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15532&path=/branches/ScribusOIF/scribus/third_party/CMakeLists.txt
==============================================================================
--- branches/ScribusOIF/scribus/third_party/CMakeLists.txt (original)
+++ branches/ScribusOIF/scribus/third_party/CMakeLists.txt Wed Oct 13 14:05:38 2010
@@ -11,3 +11,5 @@
 ENDIF(HAVE_BOOST)
 
 ADD_SUBDIRECTORY(wpg)
+
+ADD_SUBDIRECTORY(harfbuzz/src)




More information about the scribus-commit mailing list