View Issue Details

IDProjectCategoryView StatusLast Update
0016128ScribusImport / Exportpublic2020-06-21 12:39
Reporteroliverthered Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionduplicate 
PlatformanyOSanyOS Versionany
Product Version1.5.6.svn 
Summary0016128: implement some more on the basic pdf text import, framework, abstract addchar and ui for selecting import method
Descriptionimplement some more on the basic pdf text import,
 framework more fully integrated with settextpos and no configures the correct class to use for the newly abstracted addchar.,
you can now select if you want to import a pdf as text or as vectors in the plugin GUI.
addChar has been abstracted out to provide a variety of different functionality based on the start of the pdf document import.
compleatly remove m_text_position &co.
implement updateTextPos
Steps To Reproducetry to import a pdsf file with text in it.
Additional Informationpatches are in the following order:
updateTextPos.diff
uisetimporttextasvectors.diff
morefullyintergratetheframeworkandsettextpos.diff
abstractOutAddChar.diff
Tagsimport, patch, PDF, pdf import
PatchYes

Relationships

duplicate of 0016142 closedjghali Preliminary support for importing PDF text as text 

Activities

oliverthered

2020-06-03 19:31

reporter  

updateTextPos.diff (2,947 bytes)   
 scribus/plugins/import/pdf/slaoutput.cpp | 38 ++++++++++++++++++++++++++++++++
 scribus/plugins/import/pdf/slaoutput.h   |  3 ++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp
index c98d3d9ec..ce58cab02 100644
--- a/scribus/plugins/import/pdf/slaoutput.cpp
+++ b/scribus/plugins/import/pdf/slaoutput.cpp
@@ -4180,3 +4180,41 @@ void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* text_node)
 	}
 }
 
+/**
+ * \brief Updates current text position
+ */
+void SlaOutputDev::updateTextPos(GfxState* state) {
+	qDebug() << "updateTextPos()";
+
+	QPointF new_position = QPointF(state->getCurX(), state->getCurY());
+	//TODO: Implement this in the framework when new_position indicates a new text region should be created.
+	if (m_glyphs.empty())
+	{
+		//FIXME: Actually put this in the correct class	
+			//QPointF textRegionOrigin = new_position;
+		m_activeTextRegion->textRegioBasenOrigin = new_position;
+	}
+	else
+	{
+		// a delayed call using the last glyph that was put onto the stack. it will be a glyph situated on the far side bounds of the text region
+		addGlyphAtPoint(m_glyphs.back().position, m_glyphs.back());
+	}
+	//FIXME: I think _moveToPoint should do some of this. actually the first time innitialization is needed
+	if (m_activeTextRegion->_lineBaseXY == QPointF(-1, -1)) {
+		m_activeTextRegion->_lineBaseXY = new_position;
+	}
+	if (m_activeTextRegion->_lastXY == QPointF(-1, -1))
+	{
+		m_activeTextRegion->_lastXY = new_position;
+	}
+	moveToPoint(new_position);
+	//TODO: See if text position is still needed
+	m_text_position = new_position;
+	/* TODO: Implement this in the framework
+	QPointF d = QPointF(abs(m_text_position.x() - new_position.x()), new_position.y() - m_text_position.y());
+	
+	if (_in_text_object && d.x() > 10 && d.y() > 10) {
+		_flushText(state);
+	}
+	*/
+}
diff --git a/scribus/plugins/import/pdf/slaoutput.h b/scribus/plugins/import/pdf/slaoutput.h
index 017b871bc..926d8e4ae 100644
--- a/scribus/plugins/import/pdf/slaoutput.h
+++ b/scribus/plugins/import/pdf/slaoutput.h
@@ -356,6 +356,7 @@ private:
 	void addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph);
 	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen);
 	void setFillAndStrokeForPDF(GfxState* state, PageItem* text_node);
+	void updateTextPos(GfxState* state) override;
 
 	bool pathIsClosed {false};
 	QString CurrColorFill;
@@ -428,7 +429,7 @@ private:
 	std::vector<PdfGlyph> m_glyphs; //this may replace some of the other settings or it may not, certainly not font as text gets flushed if the font changes
 
 	//PDF Text import
-	QPoint m_text_position = QPoint(0,0);
+	QPointF m_text_position = QPointF(0,0);
 };
 
 #endif
updateTextPos.diff (2,947 bytes)   
abstractOutAddChar.diff (14,922 bytes)   
 scribus/plugins/import/pdf/slaoutput.cpp | 167 ++++++++++++++++++-------------
 scribus/plugins/import/pdf/slaoutput.h   |  75 ++++++++++++--
 2 files changed, 165 insertions(+), 77 deletions(-)

diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp
index fe29fd8d2..d050077d4 100644
--- a/scribus/plugins/import/pdf/slaoutput.cpp
+++ b/scribus/plugins/import/pdf/slaoutput.cpp
@@ -284,6 +284,8 @@ SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringL
 	currentLayer = m_doc->activeLayer();
 	layersSetByOCG = false;
 	importTextAsVectors - true;
+	//FIXME: can probably have an array of these instead of creting new ones and deleting them
+	addChar = new AddFirstChar(this);
 }
 
 SlaOutputDev::~SlaOutputDev()
@@ -3328,7 +3330,7 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub
 				}
 				if ((textPath.size() > 3) && ((wh.x() != 0.0) || (wh.y() != 0.0)) && (textRenderingMode != 7))
 				{
-					PageItem* text_node = NULL;
+					PageItem* text_node = nullptr;
 
 
 					int z = m_doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, xCoor, yCoor, 10, 10, 0, CommonStrings::None, CommonStrings::None);
@@ -3355,8 +3357,8 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub
 				delete fontPath;
 			}
 		}
-		if (!importTextAsVectors) { // donm't render the char as vectors add it to an array so it can be rendred as a string
-			addChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
+		if (!importTextAsVectors) { // donm't render the char as vectors add it to an array so it can be rendred as a string			
+			addChar->addChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
 		}
 	}
 }
@@ -4009,21 +4011,23 @@ void SlaOutputDev::moveToPoint(QPointF newPoint)
 	// if nothing can be done then write out the textregioin and delete it and create a new trextrext and re-adcfd ther char, set the pos etc...
 	if (pass == false)
 	{
-		//FIXME: ... there should actually be a vector of these because we don't want to delete them
-		//TODO: _flushText();pdf
-		//TODO: render the m_activeTextRegion
+		
+
+		// redner the textframe
 		renderTextFrame();
+		//FIXME:  there should actually be a vector of these because we don't want to delete them
 		delete m_activeTextRegion;
 		//Create and initilize a new TextRegion
 
 		m_activeTextRegion = new TextRegion();
-		//if (m_glyphs.size() == 0)
-		//{
-		
+		delete addChar;
+		addChar = new AddFirstChar(this);
+
+		/*TOPDO: DXo we need to initlize thease
 		m_activeTextRegion->textRegioBasenOrigin = newPoint;
-		//}
 		m_activeTextRegion->_lineBaseXY = newPoint;
 		m_activeTextRegion->_lastXY = newPoint;
+		*/
 	}
 }
 
@@ -4044,17 +4048,24 @@ void SlaOutputDev::addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph) {
 
 	// if nothing can be done then write out the textregioin and delete it and create a new trextrext and re-adcfd ther char, set the pos etc...
 	if (pass == false) {
-		//TODO: _flushText();  the textregion should get written out to scribus here, or alternativlty. instead of deleting it keep all the textregions in a vector and update scribus at the end. this may have better performance as the code footprint will in two smalkler bits instead of one large bit so cpu cache may be able to manage more
+
+		renderTextFrame();
+		// FIXME: There should be an arracy of thease and they should all be rendered at the end instead of rendering them as one offs and deleting them all the time
 		delete m_activeTextRegion;
-		m_activeTextRegion = new TextRegion();//TODO: newGlyphPoint);
-		//TODO: initialize m_activeTextRegion based on newGlyphPoint and new_glyph
+		//Create and initilize a new TextRegion
+		m_activeTextRegion = new TextRegion();
+
+		//initialize m_activeTextRegion based on newGlyphPoint and new_glyph
+		addGlyphAtPoint(newGlyphPoint, new_glyph);
+		delete addChar;
+		addChar = new AddBasicChar(this);
 	}
 	else {
 		//TODO: possible don't store the glyphs on the textRegion, well certainly not like this, we only need to check bounbdry and feature positions
 		//m_activeTextRegion->glyphs.push_back(new_glyph);
 
 		//at the moment a new segment only gets added when the line is created. a new segment should also get added if there's any change in style or layout etc...but that feature can be added llater, it's not needed for basic textframe support with no style.
-		m_activeTextRegion->textRegionLines.back().glyphIndex = m_glyphs.size() - 1;
+		m_activeTextRegion->textRegionLines.back().glyphIndex = glyphs.size() - 1;
 		if (m_activeTextRegion->textRegionLines.back().segments.empty())
 		{
 			// add a new segment
@@ -4078,67 +4089,13 @@ void SlaOutputDev::addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph) {
 			// update the text line and segment widths,
 			TextRegionLine& segment = m_activeTextRegion->textRegionLines.back().segments.back();
 			segment.width = movedGlyphPoint.x() - segment.baseOrigin.x();
-			segment.glyphIndex = m_glyphs.size() - 1;
+			segment.glyphIndex = glyphs.size() - 1;
 			m_activeTextRegion->textRegionLines.back().width = movedGlyphPoint.x() - m_activeTextRegion->textRegionLines.back().baseOrigin.x();
 		}
 		m_activeTextRegion->_lastXY = movedGlyphPoint;
 	}
 }
 
-/**
- * \brief Adds the specified character to the text buffer
- * Takes care of converting it to UTF-8 and generates a new style repr if style
- * has changed since the last call.
- */
-void SlaOutputDev::addChar(GfxState* state, double x, double y,
-	double dx, double dy,
-	double originX, double originY,
-	CharCode code, int nBytes, Unicode const* u, int uLen) {
-	qDebug() << "addChar() '" << u << " : " << uLen;
-	// TODO: Compleatly gut this function so all that it ends up doing is placing a character and some positioning information on a stack get rid of all the other junk as it's not needed
-
-	bool is_space = (uLen == 1 && u[0] == 32);
-	// Skip beginning space
-	if (is_space && m_glyphs.empty()) {
-		QPoint delta(dx, dy);
-		m_text_position += delta;
-		return;
-	}
-	// Allow only one space in a row
-	if (is_space &&
-		(m_glyphs[m_glyphs.size() - 1].code == QChar::SpecialCharacter::Space)) {
-		QPoint delta(dx, dy);
-		m_text_position += delta;
-		return;
-	}
-
-	PdfGlyph new_glyph;
-	new_glyph.is_space = is_space;
-	new_glyph.position = QPoint(x - originX, y - originY);
-	//TODO:work out if this is still needed
-	//new_glyph.text_position = m_text_position;
-	new_glyph.dx = dx;
-	new_glyph.dy = dy;
-	//TODO: This only need to be called for the very first point, replace with an abstract version of addchar that does this for brand new textregions so there's no need to record dx or dy or check is glyphs is empty or empty glyphs
-	if (m_glyphs.empty())
-	{
-		addGlyphAtPoint(QPointF(x, y), new_glyph);
-	}
-	//TODO:work out if this is still needed
-	QPoint delta(dx, dy);
-	m_text_position += delta;
-
-	// Convert the character to UTF-16 since that's our SVG document's encoding
-	{
-		for (int i = 0; i < uLen; i++) {
-			new_glyph.code += (char16_t)u[i];
-		}
-	}
-
-	new_glyph.rise = state->getRise();
-	m_glyphs.push_back(new_glyph);
-}
-
 void SlaOutputDev::setFillAndStrokeForPDF(GfxState* state, PageItem* text_node) {
 
 	text_node->ClipEdited = true;
@@ -4214,7 +4171,7 @@ void SlaOutputDev::updateTextPos(GfxState* state) {
 	else
 	{
 		// a delayed call using the last glyph that was put onto the stack. it will be a glyph situated on the far side bounds of the text region
-		addGlyphAtPoint(m_glyphs.back().position, m_glyphs.back());
+		addGlyphAtPoint(glyphs.back().position, glyphs.back());
 	}
 
 	moveToPoint(new_position);
@@ -4224,3 +4181,73 @@ void SlaOutputDev::renderTextFrame()
 {
 	//TODO: Implement, this should all be based on tyhe framework and using m_activeTextRegion
 }
+
+
+void AddFirstChar::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen)
+{
+	qDebug() << "addChar() '" << u << " : " << uLen;	
+	bool is_space = (uLen == 1 && u[0] == 32);
+	// Skip beginning space
+	if (is_space) {
+		return;
+	}
+
+	PdfGlyph new_glyph;
+	new_glyph.is_space = false;
+	new_glyph.position = QPoint(x - originX, y - originY);
+	new_glyph.dx = dx;
+	new_glyph.dy = dy;
+
+	//FIXME: have an array of differnt types of addchar class instead of creating and destroying them all the time
+	delete m_slaOutputDev->addChar;
+	m_slaOutputDev->addChar = new AddBasicChar(m_slaOutputDev);
+
+	//only need to be called for the very first point
+	m_slaOutputDev->addGlyphAtPoint(QPointF(x, y), new_glyph);
+
+	// Convert the character to UTF-16 since that's our SVG document's encoding	
+	for (int i = 0; i < uLen; i++) {
+		new_glyph.code += (char16_t)u[i];
+	}
+	
+	new_glyph.rise = state->getRise();
+	m_slaOutputDev->glyphs.push_back(new_glyph);
+
+}
+
+void AddBasicChar::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen)
+{
+	qDebug() << "addChar() '" << u << " : " << uLen;
+	// TODO: Compleatly gut this function so all that it ends up doing is placing a character and some positioning information on a stack get rid of all the other junk as it's not needed
+
+	bool is_space = (uLen == 1 && u[0] == 32);
+
+	// Allow only one space in a row
+	if (is_space &&
+		(m_slaOutputDev->glyphs[m_slaOutputDev->glyphs.size() - 1].code == QChar::SpecialCharacter::Space)) {
+		return;
+	}
+
+	PdfGlyph new_glyph;
+	new_glyph.is_space = is_space;
+	new_glyph.position = QPoint(x - originX, y - originY);
+	new_glyph.dx = dx;
+	new_glyph.dy = dy;
+
+	// Convert the character to UTF-16 since that's our SVG document's encoding
+
+	for (int i = 0; i < uLen; i++) {
+		new_glyph.code += (char16_t)u[i];
+	}
+
+	new_glyph.rise = state->getRise();
+	m_slaOutputDev->glyphs.push_back(new_glyph);
+}
+
+void AddCharWithPreviousStyle::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen)
+{
+}
+
+void AddCharWithNewStyle::addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen)
+{
+}
diff --git a/scribus/plugins/import/pdf/slaoutput.h b/scribus/plugins/import/pdf/slaoutput.h
index 937f752d9..a179ac285 100644
--- a/scribus/plugins/import/pdf/slaoutput.h
+++ b/scribus/plugins/import/pdf/slaoutput.h
@@ -191,6 +191,13 @@ public:
 	QPointF _lastXY = QPointF(-1, -1);
 };
 
+class AddCharInterface
+{
+public:
+	// Pure Virtual Function 
+	virtual void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) = 0;
+};
+
 class SlaOutputDev : public OutputDev
 {
 public:
@@ -312,6 +319,11 @@ public:
 	void  type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/) override;
 	void  type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/) override;
 
+	//text as text
+	void addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph);
+	std::vector<PdfGlyph> glyphs; //this may replace some of the other settings or it may not, certainly not font as text gets flushed if the font changes
+	AddCharInterface* addChar = nullptr;
+
 	//----- form XObjects
 	void drawForm(Ref /*id*/) override { qDebug() << "Draw Form"; }
 
@@ -352,9 +364,8 @@ private:
 	bool adjunctLesser(qreal testY, qreal lastY, qreal baseY);
 	bool adjunctGreater(qreal testY, qreal lastY, qreal baseY);
 	bool linearTest(QPointF point, bool xInLimits, bool yInLimits);
-	void moveToPoint(QPointF newPoint);
-	void addGlyphAtPoint(QPointF newGlyphPoint, PdfGlyph new_glyph);
-	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen);
+	void moveToPoint(QPointF newPoint);	
+	//void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen);
 	void setFillAndStrokeForPDF(GfxState* state, PageItem* text_node);
 	void updateTextPos(GfxState* state) override;
 	void renderTextFrame();
@@ -426,11 +437,61 @@ private:
 	int m_actPage;
 
 	//PDF Textbox framework
-	TextRegion *m_activeTextRegion = NULL;
-	std::vector<PdfGlyph> m_glyphs; //this may replace some of the other settings or it may not, certainly not font as text gets flushed if the font changes
+	TextRegion *m_activeTextRegion = nullptr;		
+};
+
+class AddFirstChar : public AddCharInterface
+{
+
+public:
+	AddFirstChar(SlaOutputDev *slaOutputDev)
+	{
+		m_slaOutputDev = slaOutputDev;
+	}
+	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override;
+private:
+	SlaOutputDev* m_slaOutputDev = nullptr;
+};
+
+class AddBasicChar : public AddCharInterface
+{
+
+public:
+	AddBasicChar(SlaOutputDev* slaOutputDev)
+	{
+		m_slaOutputDev = slaOutputDev;
+	}
+	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override;
+private:
+	SlaOutputDev* m_slaOutputDev = nullptr;
+};
 
-	//PDF Text import
-	QPointF m_text_position = QPointF(0,0);
+// TODO: implement these addchar definitions so that they can handle changes in style, font, text micro positioning, scaling, matrix etc...
+class AddCharWithNewStyle : public AddCharInterface
+{
+
+public:
+	AddCharWithNewStyle(SlaOutputDev* slaOutputDev)
+	{
+		m_slaOutputDev = slaOutputDev;
+	}
+	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override;
+private:
+	SlaOutputDev* m_slaOutputDev = nullptr;
+};
+
+// TODO: implement these addchar definitions so that they can handle changes in style, font, text micro positioning, scaling, matrix etc...
+class AddCharWithPreviousStyle : public AddCharInterface
+{
+
+public:
+	AddCharWithPreviousStyle(SlaOutputDev* slaOutputDev)
+	{
+		m_slaOutputDev = slaOutputDev;
+	}
+	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen) override;
+private:
+	SlaOutputDev* m_slaOutputDev = nullptr;
 };
 
 #endif
abstractOutAddChar.diff (14,922 bytes)   
morefullyintergratetheframeworkandsettextpos.diff (4,070 bytes)   
 scribus/plugins/import/pdf/slaoutput.cpp | 47 ++++++++++++++++----------------
 scribus/plugins/import/pdf/slaoutput.h   |  1 +
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp
index d1fe76f68..fe29fd8d2 100644
--- a/scribus/plugins/import/pdf/slaoutput.cpp
+++ b/scribus/plugins/import/pdf/slaoutput.cpp
@@ -3972,6 +3972,15 @@ bool SlaOutputDev::linearTest(QPointF point, bool xInLimits, bool yInLimits) {
 
 void SlaOutputDev::moveToPoint(QPointF newPoint)
 {
+	// Do some initilization if we are in a new text region
+	if (m_activeTextRegion->_lineBaseXY == QPointF(-1, -1))
+	{
+		m_activeTextRegion->_lineBaseXY = newPoint;
+	}
+	if (m_activeTextRegion->_lastXY == QPointF(-1, -1))
+	{
+		m_activeTextRegion->_lastXY = newPoint;
+	}
 	//TODO: I need to write down which ones we want so I can work it all out, for now just some basic fuzzy matching support.
 	bool xInLimits = false;
 	if (closeToX(newPoint.x(), m_activeTextRegion->_lastXY.x()))
@@ -4003,14 +4012,16 @@ void SlaOutputDev::moveToPoint(QPointF newPoint)
 		//FIXME: ... there should actually be a vector of these because we don't want to delete them
 		//TODO: _flushText();pdf
 		//TODO: render the m_activeTextRegion
+		renderTextFrame();
 		delete m_activeTextRegion;
 		//Create and initilize a new TextRegion
 
 		m_activeTextRegion = new TextRegion();
-		if (m_glyphs.size() == 0)
-		{
-			m_activeTextRegion->textRegioBasenOrigin = newPoint;
-		}
+		//if (m_glyphs.size() == 0)
+		//{
+		
+		m_activeTextRegion->textRegioBasenOrigin = newPoint;
+		//}
 		m_activeTextRegion->_lineBaseXY = newPoint;
 		m_activeTextRegion->_lastXY = newPoint;
 	}
@@ -4192,34 +4203,24 @@ void SlaOutputDev::updateTextPos(GfxState* state) {
 	qDebug() << "updateTextPos()";
 
 	QPointF new_position = QPointF(state->getCurX(), state->getCurY());
-	//TODO: Implement this in the framework when new_position indicates a new text region should be created.
-	if (m_glyphs.empty())
+	//check to see if we are in a new text region
+	if (m_activeTextRegion->textRegioBasenOrigin == QPointF(-1, -1))
 	{
 		//FIXME: Actually put this in the correct class	
 			//QPointF textRegionOrigin = new_position;
 		m_activeTextRegion->textRegioBasenOrigin = new_position;
+
 	}
 	else
 	{
 		// a delayed call using the last glyph that was put onto the stack. it will be a glyph situated on the far side bounds of the text region
 		addGlyphAtPoint(m_glyphs.back().position, m_glyphs.back());
 	}
-	//FIXME: I think _moveToPoint should do some of this. actually the first time innitialization is needed
-	if (m_activeTextRegion->_lineBaseXY == QPointF(-1, -1)) {
-		m_activeTextRegion->_lineBaseXY = new_position;
-	}
-	if (m_activeTextRegion->_lastXY == QPointF(-1, -1))
-	{
-		m_activeTextRegion->_lastXY = new_position;
-	}
+
 	moveToPoint(new_position);
-	//TODO: See if text position is still needed
-	m_text_position = new_position;
-	/* TODO: Implement this in the framework
-	QPointF d = QPointF(abs(m_text_position.x() - new_position.x()), new_position.y() - m_text_position.y());
-	
-	if (_in_text_object && d.x() > 10 && d.y() > 10) {
-		_flushText(state);
-	}
-	*/
+
+}
+void SlaOutputDev::renderTextFrame()
+{
+	//TODO: Implement, this should all be based on tyhe framework and using m_activeTextRegion
 }
diff --git a/scribus/plugins/import/pdf/slaoutput.h b/scribus/plugins/import/pdf/slaoutput.h
index b4f19a926..937f752d9 100644
--- a/scribus/plugins/import/pdf/slaoutput.h
+++ b/scribus/plugins/import/pdf/slaoutput.h
@@ -357,6 +357,7 @@ private:
 	void addChar(GfxState* state, double x, double y, double dx, double dy, double originX, double originY, CharCode code, int nBytes, Unicode const* u, int uLen);
 	void setFillAndStrokeForPDF(GfxState* state, PageItem* text_node);
 	void updateTextPos(GfxState* state) override;
+	void renderTextFrame();
 
 	bool pathIsClosed {false};
 	QString CurrColorFill;
uisetimporttextasvectors.diff (7,627 bytes)   
 scribus/plugins/import/pdf/importpdf.cpp        |  3 +++
 scribus/plugins/import/pdf/pdfimportoptions.cpp |  7 +++++
 scribus/plugins/import/pdf/pdfimportoptions.h   |  1 +
 scribus/plugins/import/pdf/pdfimportoptions.ui  | 35 +++++++++++++++++++++++++
 scribus/plugins/import/pdf/slaoutput.cpp        |  9 +++++--
 scribus/plugins/import/pdf/slaoutput.h          |  2 +-
 6 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/scribus/plugins/import/pdf/importpdf.cpp b/scribus/plugins/import/pdf/importpdf.cpp
index 0c653cd2b..d143cb350 100644
--- a/scribus/plugins/import/pdf/importpdf.cpp
+++ b/scribus/plugins/import/pdf/importpdf.cpp
@@ -430,6 +430,7 @@ bool PdfPlug::convert(const QString& fn)
 				else if (getCBox(Art_Box, 1) != mediaRect)
 					boxesAreDifferent = true;
 				bool cropped = false;
+				bool importTextAsVectors = true;
 				int contentRect = Media_Box;
 				if (((interactive) || (importerFlags & LoadSavePlugin::lfCreateDoc)) && ((lastPage > 1) || boxesAreDifferent))
 				{
@@ -455,6 +456,7 @@ bool PdfPlug::convert(const QString& fn)
 					cropped = optImp->croppingEnabled();
 					if (!cropped)
 						crop = cropped;
+					importTextAsVectors = optImp->getImportAsVectors();
 					// When displaying  pages slices, we should always set useMediaBox to true
 					// in order to use MediaBox (x, y) as coordinate system
 					if (contentRect != Media_Box)
@@ -471,6 +473,7 @@ bool PdfPlug::convert(const QString& fn)
 				SlaOutputDev *dev = new SlaOutputDev(m_Doc, &Elements, &importedColors, importerFlags);
 				if (dev->isOk())
 				{
+					dev->importTextAsVectors = importTextAsVectors;
 					OCGs* ocg = pdfDoc->getOptContentConfig();
 					if (ocg)
 					{
diff --git a/scribus/plugins/import/pdf/pdfimportoptions.cpp b/scribus/plugins/import/pdf/pdfimportoptions.cpp
index e7f8ca060..195d942c7 100644
--- a/scribus/plugins/import/pdf/pdfimportoptions.cpp
+++ b/scribus/plugins/import/pdf/pdfimportoptions.cpp
@@ -61,6 +61,11 @@ bool PdfImportOptions::croppingEnabled()
 	return ui->cropGroup->isChecked();
 }
 
+bool PdfImportOptions::getImportAsVectors()
+{
+	return ui->textAsVectors->isChecked();
+}
+
 void PdfImportOptions::setUpOptions(const QString& fileName, int actPage, int numPages, bool interact, bool cropPossible, PdfPlug* plug)
 {
 	m_plugin = plug;
@@ -71,6 +76,8 @@ void PdfImportOptions::setUpOptions(const QString& fileName, int actPage, int nu
 	ui->cropGroup->setVisible(cropPossible);
 	ui->cropGroup->setChecked(cropPossible);
 	ui->cropBox->setCurrentIndex(3); // Use CropBox by default
+	ui->textAsVectors->setChecked(true);
+	ui->textAsText->setChecked(false);
 	if (interact)
 	{
 		ui->allPages->setChecked(false);
diff --git a/scribus/plugins/import/pdf/pdfimportoptions.h b/scribus/plugins/import/pdf/pdfimportoptions.h
index 9150cf3b7..493dd6791 100644
--- a/scribus/plugins/import/pdf/pdfimportoptions.h
+++ b/scribus/plugins/import/pdf/pdfimportoptions.h
@@ -25,6 +25,7 @@ public:
 	QString getPagesString();
 	int getCropBox();
 	bool croppingEnabled();
+	bool getImportAsVectors();
 	void paintEvent(QPaintEvent *e);
 
 protected:
diff --git a/scribus/plugins/import/pdf/pdfimportoptions.ui b/scribus/plugins/import/pdf/pdfimportoptions.ui
index ba592920d..f03ee1048 100644
--- a/scribus/plugins/import/pdf/pdfimportoptions.ui
+++ b/scribus/plugins/import/pdf/pdfimportoptions.ui
@@ -175,6 +175,41 @@
          </layout>
         </widget>
        </item>
+        <item>
+          <widget class="QGroupBox" name="groupBox_2">
+            <property name="sizePolicy">
+              <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+                <horstretch>0</horstretch>
+                <verstretch>0</verstretch>
+              </sizepolicy>
+            </property>
+            <property name="title">
+              <string/>
+            </property>
+            <layout class="QVBoxLayout" name="verticalLayout_8">
+              <item>
+                <widget class="QRadioButton" name="textAsVectors">
+                  <property name="enabled">
+                    <bool>true</bool>
+                  </property>
+                  <property name="text">
+                    <string>Import Text As Vectors</string>
+                  </property>
+                  <property name="checked">
+                    <bool>true</bool>
+                  </property>
+                </widget>
+              </item>
+              <item>
+                <widget class="QRadioButton" name="textAsText">
+                  <property name="text">
+                    <string>Import Text As Text</string>
+                  </property>
+                </widget>
+              </item>
+            </layout>
+          </widget>
+        </item>               
        <item>
         <spacer name="verticalSpacer">
          <property name="orientation">
diff --git a/scribus/plugins/import/pdf/slaoutput.cpp b/scribus/plugins/import/pdf/slaoutput.cpp
index ce58cab02..d1fe76f68 100644
--- a/scribus/plugins/import/pdf/slaoutput.cpp
+++ b/scribus/plugins/import/pdf/slaoutput.cpp
@@ -283,6 +283,7 @@ SlaOutputDev::SlaOutputDev(ScribusDoc* doc, QList<PageItem*> *Elements, QStringL
 	importerFlags = flags;
 	currentLayer = m_doc->activeLayer();
 	layersSetByOCG = false;
+	importTextAsVectors - true;
 }
 
 SlaOutputDev::~SlaOutputDev()
@@ -3314,7 +3315,7 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub
 			FPointArray textPath;
 			textPath.fromQPainterPath(qPath);
 			FPoint wh = textPath.widthHeight();
-			if (m_import_text_as_vectors) {
+			if (importTextAsVectors) {
 				qDebug() << "drawChar() ";
 
 				if (textRenderingMode > 3)
@@ -3354,7 +3355,7 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub
 				delete fontPath;
 			}
 		}
-		if (!m_import_text_as_vectors) { // donm't render the char as vectors add it to an array so it can be rendred as a string
+		if (!importTextAsVectors) { // donm't render the char as vectors add it to an array so it can be rendred as a string
 			addChar(state, x, y, dx, dy, originX, originY, code, nBytes, u, uLen);
 		}
 	}
@@ -3363,6 +3364,8 @@ void SlaOutputDev::drawChar(GfxState* state, double x, double y, double dx, doub
 GBool SlaOutputDev::beginType3Char(GfxState *state, double x, double y, double dx, double dy, CharCode code, POPPLER_CONST_082 Unicode *u, int uLen)
 {
 //	qDebug() << "beginType3Char";
+	if (importTextAsVectors == false)
+		return gTrue;
 	GfxFont *gfxFont;
 	if (!(gfxFont = state->getFont()))
 		return gTrue;
@@ -3378,6 +3381,8 @@ GBool SlaOutputDev::beginType3Char(GfxState *state, double x, double y, double d
 void SlaOutputDev::endType3Char(GfxState *state)
 {
 //	qDebug() << "endType3Char";
+	if (importTextAsVectors == false)
+		return;
 	F3Entry f3e = m_F3Stack.pop();
 	groupEntry gElements = m_groupStack.pop();
 	m_doc->m_Selection->clear();
diff --git a/scribus/plugins/import/pdf/slaoutput.h b/scribus/plugins/import/pdf/slaoutput.h
index 926d8e4ae..b4f19a926 100644
--- a/scribus/plugins/import/pdf/slaoutput.h
+++ b/scribus/plugins/import/pdf/slaoutput.h
@@ -301,7 +301,7 @@ public:
 	void updateFillColor(GfxState *state) override;
 	void updateStrokeColor(GfxState *state) override;
 	void updateFontForVector(GfxState* state);
-	bool m_import_text_as_vectors = true;
+	bool importTextAsVectors;
 
 	//----- text drawing
 	void  beginTextObject(GfxState *state) override;
uisetimporttextasvectors.diff (7,627 bytes)   

jghali

2020-06-03 21:36

administrator   ~0047668

As in 0016125, patches do not follow properly our code style:
- braces must be on their own line
- if a code block has a single line, then no braces
- variable naming: m_import_text_as_vectors => not correct, use m_importTextAsVectors instead
- it seems there are a few obvious typos in these patches

Issue History

Date Modified Username Field Change
2020-06-03 19:31 oliverthered New Issue
2020-06-03 19:31 oliverthered Tag Attached: import
2020-06-03 19:31 oliverthered Tag Attached: patch
2020-06-03 19:31 oliverthered Tag Attached: PDF
2020-06-03 19:31 oliverthered Tag Attached: pdf import
2020-06-03 19:31 oliverthered File Added: updateTextPos.diff
2020-06-03 19:31 oliverthered File Added: abstractOutAddChar.diff
2020-06-03 19:31 oliverthered File Added: morefullyintergratetheframeworkandsettextpos.diff
2020-06-03 19:31 oliverthered File Added: uisetimporttextasvectors.diff
2020-06-03 21:36 jghali Note Added: 0047668
2020-06-21 12:39 jghali Assigned To => jghali
2020-06-21 12:39 jghali Status new => resolved
2020-06-21 12:39 jghali Resolution open => duplicate
2020-06-21 12:39 jghali Relationship added duplicate of 0016142
2020-06-21 12:39 jghali Status resolved => closed