r22718 by jghali - some refactoring for ftface.cpp and scfontmetrics.cpp

scribus-commit scribus-commit at lists.scribus.net
Fri Oct 5 16:55:50 UTC 2018


Author: jghali
Date: Fri Oct  5 16:55:50 2018
New Revision: 22718

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22718
Log:
some refactoring for ftface.cpp and scfontmetrics.cpp

Modified:
    trunk/Scribus/scribus/fonts/ftface.cpp
    trunk/Scribus/scribus/fonts/scfontmetrics.cpp

Modified: trunk/Scribus/scribus/fonts/ftface.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22718&path=/trunk/Scribus/scribus/fonts/ftface.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/ftface.cpp	(original)
+++ trunk/Scribus/scribus/fonts/ftface.cpp	Fri Oct  5 16:55:50 2018
@@ -317,7 +317,7 @@
 }
 
 
-bool FtFace::glyphNames(ScFace::FaceEncoding& GList) const
+bool FtFace::glyphNames(ScFace::FaceEncoding& glyphList) const
 {
 	char buf[50];
 	FT_ULong  charcode;
@@ -330,7 +330,7 @@
 	const bool hasPSNames = FT_HAS_GLYPH_NAMES(face);
 	
 //	qDebug() << "reading metrics for" << face->family_name << face->style_name;
-	charcode = FT_Get_First_Char(face, &gindex );
+	charcode = FT_Get_First_Char(face, &gindex);
 	while (gindex != 0)
 	{
 		bool notfound = true;
@@ -347,9 +347,9 @@
 		else
 			glEncoding.glyphName = QString(reinterpret_cast<char*>(buf));
 		glEncoding.toUnicode = QString().sprintf("%04lX", charcode);
-		GList.insert(gindex, glEncoding);
-
-		charcode = FT_Get_Next_Char(face, charcode, &gindex );
+		glyphList.insert(gindex, glEncoding);
+
+		charcode = FT_Get_Next_Char(face, charcode, &gindex);
 	}
 
 	if (!hasPSNames)
@@ -359,34 +359,34 @@
 	int maxSlot1 = face->num_glyphs;
 	for (int gindex = 1; gindex < maxSlot1; ++gindex)
 	{
-		if (GList.contains(gindex))
+		if (glyphList.contains(gindex))
 			continue;
 		if (FT_Get_Glyph_Name(face, gindex, &buf, 50))
 			continue;
-		QString glyphname(reinterpret_cast<char*>(buf));
+		QString glyphName(reinterpret_cast<char*>(buf));
 
 		charcode = 0;
-		ScFace::FaceEncoding::Iterator gli;
-		for (gli = GList.begin(); gli != GList.end(); ++gli)
-		{
-			if (glyphname == gli.value().glyphName)
+		for (auto gli = glyphList.cbegin(); gli != glyphList.cend(); ++gli)
+		{
+			const ScFace::GlyphEncoding& glEncoding = gli.value();
+			if (glyphName == glEncoding.glyphName)
 			{
-				charcode = gli.value().charcode;
+				charcode = glEncoding.charcode;
 				break;
 			}
 		}
 //		qDebug() << "\tmore: " << gindex << " '" << charcode << "' --> '" << buf << "'";
 		ScFace::GlyphEncoding glEncoding;
 		glEncoding.charcode  = static_cast<ScFace::ucs4_type>(charcode);
-		glEncoding.glyphName = glyphname;
+		glEncoding.glyphName = glyphName;
 		glEncoding.toUnicode = QString().sprintf("%04lX", charcode);
-		if ((charcode == 0) && glyphname.startsWith("uni"))
-		{
-			QString uniHexStr = uniGlyphNameToUnicode(glyphname);
+		if ((charcode == 0) && glyphName.startsWith("uni"))
+		{
+			QString uniHexStr = uniGlyphNameToUnicode(glyphName);
 			if (uniHexStr.length() > 0)
 				glEncoding.toUnicode = uniHexStr;
 		}
-		GList.insert(gindex, glEncoding);
+		glyphList.insert(gindex, glEncoding);
 	}
 
 	return true;

Modified: trunk/Scribus/scribus/fonts/scfontmetrics.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22718&path=/trunk/Scribus/scribus/fonts/scfontmetrics.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/scfontmetrics.cpp	(original)
+++ trunk/Scribus/scribus/fonts/scfontmetrics.cpp	Fri Oct  5 16:55:50 2018
@@ -71,8 +71,8 @@
 	FT_ULong  charcode;
 	FT_UInt   gindex;
 	bool foundEncoding = false;
-	int countUniCode = 0;
-	int chmapUniCode = -1;
+	int countUnicode = 0;
+	int chmapUnicode = -1;
 	int chmapCustom = -1;
 	int retVal = 0;
 	//FT_CharMap defaultEncoding = face->charmap;
@@ -81,28 +81,30 @@
 // the following line, assuming that the default charmap has the index 0
 	int defaultchmap = 0;
 	FT_ULong dbgInfo = 0;
+
 	FT_Load_Sfnt_Table( face, FT_MAKE_TAG('p','o','s','t'), 0, nullptr, &dbgInfo );
 	qDebug() << "setBestEncoding for " << FT_Get_Postscript_Name(face) << " with " << face->num_glyphs << "glyphs, hasNames=" << FT_HAS_GLYPH_NAMES(face) << ", POST size=" << dbgInfo ;
-	for(int u = 0; u < face->num_charmaps; u++)
-	{
-		FT_CharMap charmap = face->charmaps[u];
-		qDebug() << "Checking cmap " << u << "(" << charmap->platform_id << "," << charmap->encoding_id << "," << FT_Get_CMap_Language_ID(charmap) << ") format " << FT_Get_CMap_Format(charmap);
+	
+	for (int i = 0; i < face->num_charmaps; i++)
+	{
+		FT_CharMap charmap = face->charmaps[i];
+		qDebug() << "Checking cmap " << i << "(" << charmap->platform_id << "," << charmap->encoding_id << "," << FT_Get_CMap_Language_ID(charmap) << ") format " << FT_Get_CMap_Format(charmap);
 		if (charmap->encoding == FT_ENCODING_UNICODE)
 		{
-			FT_Set_Charmap(face, face->charmaps[u]);
-			chmapUniCode = u;
+			FT_Set_Charmap(face, face->charmaps[i]);
+			chmapUnicode = i;
 			gindex = 0;
 			charcode = FT_Get_First_Char(face, &gindex);
-			while ( gindex != 0 )
+			while (gindex != 0)
 			{
-				countUniCode++;
+				countUnicode++;
 				charcode = FT_Get_Next_Char(face, charcode, &gindex);
 			}
-			qDebug() << "found Unicode enc for" << face->family_name << face->style_name  << "as map" << chmapUniCode << "with" << countUniCode << "glyphs";
+			qDebug() << "found Unicode enc for" << face->family_name << face->style_name  << "as map" << chmapUnicode << "with" << countUnicode << "glyphs";
 		}
 		if (charmap->encoding == FT_ENCODING_ADOBE_CUSTOM)
 		{
-			chmapCustom = u;
+			chmapCustom = i;
 			foundEncoding = true;
 			retVal = 1;
 			qDebug() << "found Custom enc for" << face->family_name << face->style_name;
@@ -112,17 +114,17 @@
 		{
 			qDebug() << "found Symbol enc for" << face->family_name << face->style_name;
 
-			chmapCustom = u;
+			chmapCustom = i;
 			foundEncoding = true;
 			retVal = 2;
 			break;
 		}
 	}
 	int mapToSet = defaultchmap;
-	if (chmapUniCode >= 0 && countUniCode >= face->num_glyphs-1)
+	if (chmapUnicode >= 0 && countUnicode >= face->num_glyphs-1)
 	{
 		qDebug() << "using Unicode enc for" << face->family_name << face->style_name;
-		mapToSet = chmapUniCode;
+		mapToSet = chmapUnicode;
 		retVal = 0;
 	}
 	else if (foundEncoding)
@@ -139,8 +141,8 @@
 
 	//Fixes #2199, missing glyphs from 1.2.1->1.2.2
 	//If the currently wanted character map is not already Unicode...
-	//if (FT_Get_Charmap_Index(face->charmap)!=chmapUniCode)
-	if (mapToSet != chmapUniCode)
+	//if (FT_Get_Charmap_Index(face->charmap)!=chmapUnicode)
+	if (mapToSet != chmapUnicode)
 	{
 		//Change map so we can count the chars in it
 		FT_Set_Charmap(face, face->charmaps[mapToSet]);
@@ -156,10 +158,10 @@
 		//If the last Unicode map we found before has more characters,
 		//then set it to be the current map.
 		
-		if (countUniCode > countCurrMap)
+		if (countUnicode > countCurrMap)
 		{
 //			qDebug() << "override with Unicode enc for" << face->family_name << face->style_name << "map" << mapToSet << "has only" << countCurrMap << "glyphs";
-			mapToSet = chmapUniCode;
+			mapToSet = chmapUnicode;
 			retVal = 0;
 		}
 	}




More information about the scribus-commit mailing list