r16767 by fschmid - PDF-Import: implemented colored and uncolored Type3 Fonts.

scribus-commit scribus-commit at lists.scribus.net
Fri Aug 5 22:35:45 UTC 2011


Author: fschmid
Date: Fri Aug  5 22:35:45 2011
New Revision: 16767

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16767
Log:
PDF-Import: implemented colored and uncolored Type3 Fonts.

Modified:
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
    trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16767&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp Fri Aug  5 22:35:45 2011
@@ -1710,6 +1710,7 @@
 
 GBool SlaOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, Unicode *u, int uLen)
 {
+//	qDebug() << "beginType3Char";
 	double *ctm;
 	ctm = state->getCTM();
 	QTransform orig_ctm = QTransform(ctm[0], ctm[1], ctm[2], ctm[3], ctm[4], ctm[5]);
@@ -1728,13 +1729,17 @@
 		QLineF tline = orig_ctm.map(cline);
 		double xCoor = m_doc->currentPage()->xOffset();
 		double yCoor = m_doc->currentPage()->yOffset();
-		ScPattern pat = m_doc->docPatterns[m_Font_Pattern_Map[fRefID]];
+		ScPattern pat = m_doc->docPatterns[m_Font_Pattern_Map[fRefID].pattern];
 		QTransform mm;
 		mm.translate(0, -pat.height * tline.length());
 		mm = orig_ctm * mm;
 		int shade = 100;
 		CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-		int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CurrColorFill, CommonStrings::None, true);
+		int z = 0;
+		if (m_Font_Pattern_Map[fRefID].colored)
+			z = m_doc->itemAdd(PageItem::Symbol, PageItem::Unspecified, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CommonStrings::None, CommonStrings::None, true);
+		else
+			z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CurrColorFill, CommonStrings::None, true);
 		PageItem *b = m_doc->Items->at(z);
 		b->setWidth(pat.width * tline.length());
 		b->setHeight(pat.height * tline.length());
@@ -1750,9 +1755,15 @@
 		b->setLineEnd(PLineEnd);
 		b->setLineJoin(PLineJoin);
 		b->setTextFlowMode(PageItem::TextFlowDisabled);
-		b->setPatternMask(m_Font_Pattern_Map[fRefID]);
-		b->setMaskTransform(b->width() / pat.width * 100, b->height() / pat.height * 100, 0, 0, 0, 0, 0);
-		b->setMaskType(3);
+		if (m_Font_Pattern_Map[fRefID].colored)
+			b->setPattern(m_Font_Pattern_Map[fRefID].pattern);
+		else
+		{
+			b->setFillShade(shade);
+			b->setPatternMask(m_Font_Pattern_Map[fRefID].pattern);
+			b->setMaskTransform(b->width() / pat.width * 100, b->height() / pat.height * 100, 0, 0, 0, 0, 0);
+			b->setMaskType(3);
+		}
 		m_Elements->append(b);
 		if (m_groupStack.count() != 0)
 		{
@@ -1765,6 +1776,7 @@
 		F3Entry f3e;
 		f3e.ctm = orig_ctm;
 		f3e.glyphRef = fRefID;
+		f3e.colored = false;
 		m_F3Stack.push(f3e);
 		ctm = state->getTextMat();
 		state->setCTM(ctm[0], ctm[1], ctm[2], ctm[3], 0, 0);
@@ -1775,6 +1787,7 @@
 
 void SlaOutputDev::endType3Char(GfxState *state)
 {
+//	qDebug() << "endType3Char";
 	double *ctm;
 	ctm = state->getCTM();
 	groupEntry gElements = m_groupStack.pop();
@@ -1809,7 +1822,6 @@
 		if (m_F3Stack.count() > 0)
 		{
 			F3Entry f3e = m_F3Stack.pop();
-			m_Font_Pattern_Map.insert(f3e.glyphRef, id);
 			state->setCTM(f3e.ctm.m11(), f3e.ctm.m12(), f3e.ctm.m21(), f3e.ctm.m22(), f3e.ctm.dx(), f3e.ctm.dy());
 			QLineF cline = QLineF(0, 0, 1, 0);
 			QLineF tline = f3e.ctm.map(cline);
@@ -1820,7 +1832,11 @@
 			mm = f3e.ctm * mm;
 			int shade = 100;
 			CurrColorFill = getColor(state->getFillColorSpace(), state->getFillColor(), &shade);
-			int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CurrColorFill, CommonStrings::None, true);
+			int z = 0;
+			if (f3e.colored)
+				z = m_doc->itemAdd(PageItem::Symbol, PageItem::Unspecified, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CommonStrings::None, CommonStrings::None, true);
+			else
+				z = m_doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, xCoor + mm.dx(), yCoor + mm.dy(), pat.width * tline.length(), pat.height * tline.length(), 0, CurrColorFill, CommonStrings::None, true);
 			PageItem *b = m_doc->Items->at(z);
 			b->setWidth(pat.width * tline.length());
 			b->setHeight(pat.height * tline.length());
@@ -1829,31 +1845,46 @@
 			m_doc->RotMode(3);
 			m_doc->RotateItem(-tline.angle(), b);
 			m_doc->RotMode(0);
-			b->setFillShade(shade);
 			b->setFillEvenOdd(false);
 			b->setFillTransparency(1.0 - state->getFillOpacity());
 			b->setFillBlendmode(getBlendMode(state));
 			b->setLineEnd(PLineEnd);
 			b->setLineJoin(PLineJoin);
 			b->setTextFlowMode(PageItem::TextFlowDisabled);
-			b->setPatternMask(id);
-			b->setMaskTransform(b->width() / pat.width * 100, b->height() / pat.height * 100, 0, 0, 0, 0, 0);
-			b->setMaskType(3);
+			if (f3e.colored)
+				b->setPattern(id);
+			else
+			{
+				b->setFillShade(shade);
+				b->setPatternMask(id);
+				b->setMaskTransform(b->width() / pat.width * 100, b->height() / pat.height * 100, 0, 0, 0, 0, 0);
+				b->setMaskType(3);
+			}
 			m_Elements->append(b);
 			if (m_groupStack.count() != 0)
 			{
 				m_groupStack.top().Items.append(b);
 			}
+			F3GlyphEntry gid;
+			gid.colored = f3e.colored;
+			gid.pattern = id;
+			m_Font_Pattern_Map.insert(f3e.glyphRef, gid);
 		}
 	}
 }
 
 void SlaOutputDev::type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/)
 {
+//	qDebug() << "type3D0";
+	if (m_F3Stack.count() > 0)
+		m_F3Stack.top().colored = true;
 }
 
 void SlaOutputDev::type3D1(GfxState *state, double wx, double wy, double llx, double lly, double urx, double ury)
 {
+//	qDebug() << "type3D1";
+	if (m_F3Stack.count() > 0)
+		m_F3Stack.top().colored = false;
 }
 
 void SlaOutputDev::beginTextObject(GfxState *state)
@@ -1904,6 +1935,11 @@
 	tmp.setSpotColor(false);
 	tmp.setRegistrationColor(false);
 	*shade = 100;
+	if (m_F3Stack.count() > 0)
+	{
+		if (!m_F3Stack.top().colored)
+			return "Black";
+	}
 	if ((color_space->getMode() == csDeviceRGB) || (color_space->getMode() == csCalRGB))
 	{
 		GfxRGB rgb;

Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16767&path=/trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h Fri Aug  5 22:35:45 2011
@@ -205,9 +205,15 @@
 	{
 		QTransform ctm;
 		QString glyphRef;
+		bool colored;
 	};
 	QStack<F3Entry> m_F3Stack;
-	QMap<QString, QString> m_Font_Pattern_Map;
+	struct F3GlyphEntry
+	{
+		QString pattern;
+		bool colored;
+	};
+	QMap<QString, F3GlyphEntry> m_Font_Pattern_Map;
 	int grStackDepth;
 	int layerNum;
 	int currentLayer;




More information about the scribus-commit mailing list