Currently, if we add a font with CPage::addSystemType1Font(), it is
hard to tell what the font ID of the added font will be. The function
tries "Fonticek", "Fonticekk", "Fonticekkk", etc., until it finds one
that is unused, but we don't know which one it picked.

I propose changing the function to return the font ID of the added
font. Also, instead of using "Fonticek", I propose using "F1", "F2",
etc., for the font ID (the first one that's available), which is how
many other PDF implementations generate font IDs.

I've attached a patch implements this change. Thanks.
--- pdfedit-0.3.2/src/kernel/cpage.h	2007-04-26 05:31:52.000000000 -0400
+++ pdfedit-0.3.2/src/kernel/cpage.h	2007-11-07 21:26:39.640227000 -0500
@@ -917,16 +917,17 @@ public:
 	/**
 	 * Add new simple type 1 font item to the page resource dictionary. 
 	 *
-	 * The id of this font is arbitrary but it has to be unique. It will be generated as follows: 
-	 * PdfEditor for the first item, PdfEditorr for the second, PdfEditorrr for
-	 * the third etc.
+	 * The id of this font is arbitrary but it has to be unique.
+	 * It will be generated as F#, where # is some number.
 	 *
 	 * We supposed that the font name is a standard system font avaliable to all viewers.
 	 *
-	 * @param fontname Output container of pairs of (Id,Name).
+	 * @param fontname Name of the font to add.
 	 * @param winansienc Set encoding to standard WinAnsiEnconding.
+	 *
+	 * @return The font ID of the added font.
 	 */
-	void addSystemType1Font (const std::string& fontname, bool winansienc = true);
+	std::string addSystemType1Font (const std::string& fontname, bool winansienc = true);
 
 
 	//

--- pdfedit-0.3.2/src/kernel/cpage.cc	2007-04-26 05:59:21.000000000 -0400
+++ pdfedit-0.3.2/src/kernel/cpage.cc	2007-11-07 21:17:26.384200000 -0500
@@ -1379,7 +1379,7 @@ template size_t CPage::findText<std::vec
 //
 //
 //
-void
+std::string
 CPage::addSystemType1Font (const std::string& fontname, bool winansienc)
 {
 	// Create font dictionary
@@ -1431,27 +1431,21 @@ CPage::addSystemType1Font (const std::st
 	//
 	// Find suitable name
 	//
-	size_t len = 0;
-	bool our = false;
-	string ourfontname ("Fonticek");
+	std::set<std::string> fontnamesinuse;
 	for (Fonts::iterator it = fs.begin(); it != fs.end(); ++it)
-	{// Compare basenames and look for longest string and for PdfEdit string
-		if (ourfontname == (*it).first)
-			our = true;
-		len = std::max ((*it).first.length(), len);
-	}
+		fontnamesinuse.insert(it->first);
 
-	// Make name unique
-	if (our)
-	{/**\todo make sane */
-		len -= ourfontname.length();
-		++len;
-		for (size_t i = 0; i < len; ++i)
-			ourfontname.push_back ('k');
-	}
+	// Try F1, F2, F3, etc., until we find one that's not in use
+	std::ostringstream newfontname;
+	int i = 1;
+	do {
+		newfontname.str(""); // clear newfontname stream
+		newfontname << 'F' << i;
+		++i;
+	} while (fontnamesinuse.find(newfontname.str()) != fontnamesinuse.end());
 
 	// Add it
-	fonts->addProperty (ourfontname, *font);
+	fonts->addProperty (newfontname.str(), *font);
 	
 	//
 	// Create state and resources and update our contentstreams
@@ -1462,6 +1456,8 @@ CPage::addSystemType1Font (const std::st
 
 	for (ContentStreams::iterator it = contentstreams.begin(); it != contentstreams.end(); ++it)
 		(*it)->setGfxParams (gfxstate, gfxres);
+
+	return newfontname.str();
 }
 //
 //
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Pdfedit-support mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pdfedit-support

Reply via email to