View Issue Details

IDProjectCategoryView StatusLast Update
0009841ScribusPlug-inspublic2016-04-26 01:04
Reportermabri Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
Status newResolutionopen 
Platformx86 PCOSUbuntu LinuxOS Version10.04 LTS
Product Version1.4.0svn 
Summary0009841: [PATCH] svg plug-in doesn't import text as (editable) text
DescriptionText in imported SVG files is always converted to paths/polylines, but I need it
to be imported as text that is associated with the same font properties as in the
SVG document (it should also be editable as text).
Steps To ReproduceFile->Import->Import Vector File..., select an SVG file in the file chooser, click "OK", then click with the changed cursor there where the upper-left edge
of the import frame should be. Then an import frame will be created with the
imported vector graphic in it, but text is only imported as a path/polyline
(polygon?), but not as editable text.
Additional InformationThe SVG files I tested are from Inkscape in the distribution's version (0.48, IIRC).
This is an issue I intend to work on myself in the very near future.
I was advised on the scribus-dev mailing list on Sunday, March 13, 2011,
that I should implement a choice from import-as-vector and import-as-text,
but I haven't seen a GUI in the SVG plug-in source code, so please help me
with that (I'm subscribed to the scribus-dev mailing list).
Tags#pending
PatchYes

Relationships

has duplicate 0010125 closedjghali Font is not embedded in exported pdf from SVG text 

Activities

mabri

2011-04-04 20:25

reporter  

svgplugin-import-text-as-text.diff (3,363 bytes)   
Index: svgplugin.cpp
===================================================================
--- svgplugin.cpp	(revision 16541)
+++ svgplugin.cpp	(working copy)
@@ -20,6 +20,7 @@
 #include "customfdialog.h"
 #include "fonts/scfontmetrics.h"
 #include "fpointarray.h"
+#include "gtwriter.h"
 #include "loadsaveplugin.h"
 #include "menumanager.h"
 #include "pageitem.h"
@@ -1485,7 +1486,55 @@
 		StartX -= chunkW / 2.0;
 	else if( gc->textAnchor == "end")
 		StartX -= chunkW;
+#ifdef IMPORT_TEXT_AS_TEXT
+  QString styleBaseName = "FromSVG#";
+  double RectW = fm.boundingRect(textString).width();
+  double height = fm.height();
+  int z = m_Doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified,
+            BaseX+StartX, BaseY+StartY, RectW, height, gc->LWidth, gc->FillCol,
+            gc->StrokeCol, true);
+  PageItem* ite = m_Doc->Items->at(z);
+  qDebug() << QString("font family %1 used in SVG").arg(textFont.family());
 
+  gtWriter* writer = new gtWriter(false, ite);
+  gtFont gtfont;
+  gtfont.setFamily(textFont.family());
+  gtfont.setSize(textFont.pointSize()*10); // gtFont expects it in 1/10 pt
+  gtfont.setColor(gc->FillCol);
+  gtfont.setStrokeColor(gc->StrokeCol);
+
+  // find style named beginning with styleBaseName's value, followed by the
+  // maximal number, extract the latter, add 1 to use it for the next style
+  unsigned int styleNo = 0;
+  const StyleSet<ParagraphStyle>& pstyles = ite->doc()->paragraphStyles();
+  int paragraphStylesCount = pstyles.count(); // I hope it's constant in
+                                                    // the following for loop
+  for (int i = 0; i < paragraphStylesCount; ++i)
+  {
+      QRegExp re(styleBaseName+"[0-9]+");
+      re.setPatternSyntax(QRegExp::Wildcard);
+      QString curStyleName = pstyles[i].displayName();
+      qDebug() << QString("currently checking style %1").arg(curStyleName);
+      if (re.exactMatch(curStyleName))
+      {
+        QString numberString =
+        curStyleName.right(curStyleName.size()-styleBaseName.size());
+        unsigned int curNumber = numberString.toUInt();
+        if (curNumber > styleNo)
+          styleNo = curNumber;
+      }
+  }
+  ++styleNo;
+  gtParagraphStyle gtstyle(QString(styleBaseName+"%1").arg(styleNo));
+  // QString gtstyleName = gtstyle.getName();
+  qDebug() << QString("current style is %1").arg(gtstyle.getName());
+  gtstyle.setFont(gtfont);
+  writer->append(textString, &gtstyle);
+  delete writer;
+  ite->layout();
+  finishNode(e, ite);
+  GElements.append(ite);
+#else
 	FPointArray textPath;
 	QString textFillColor   = gc->FillCol;
 	QString textStrokeColor = gc->StrokeCol;
@@ -1501,6 +1550,7 @@
 		finishNode(e, ite);
 		GElements.append(ite);
 	}
+#endif
 	currentPos.setX( currentPos.x() + width );
 	return GElements;
 }
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt	(revision 16541)
+++ CMakeLists.txt	(working copy)
@@ -13,6 +13,11 @@
 
 SET(SCRIBUS_IMPORTSVG_PLUGIN "svgimplugin")
 
+# The experimental text-as-text importing from SVG
+IF(WANT_IMPORT_TEXT_AS_TEXT)
+  ADD_DEFINITIONS(-DIMPORT_TEXT_AS_TEXT)
+ENDIF(WANT_IMPORT_TEXT_AS_TEXT)
+
 QT4_WRAP_CPP(IMPORTSVG_PLUGIN_MOC_SOURCES ${IMPORTSVG_PLUGIN_MOC_CLASSES})
 
 ADD_LIBRARY(${SCRIBUS_IMPORTSVG_PLUGIN} MODULE ${IMPORTSVG_PLUGIN_SOURCES} ${IMPORTSVG_PLUGIN_MOC_SOURCES})

mabri

2011-04-04 20:25

reporter  

import_text_test_CMYK.svg (11,980 bytes)   
import_text_test_CMYK.svg (11,980 bytes)   

mabri

2011-04-04 20:41

reporter   ~0026003

Last edited: 2011-04-04 20:47

Please review this first version of a more-or-less working patch
(I tried it without the gtWriter API before, but it didn't work).
Positioning text imported from text-on-path is not done yet in the
patch, and especially, please tell me about getting position/size
of the text frame correct. I also discovered that the added paragraph
style would not be found in the document-global set. Is this a bug,
and should I file a separate report about it?
Sorry for not including a choice between text import as text and as
vector except at build time, please explain how to add a GUI in which
to offer such a choice.

Vladimir Savic

2011-08-10 23:15

reporter   ~0026705

Encouraging reporter and patch submitter to continue working on this! I'd like this functional too... ;)

Kunda

2016-04-26 01:04

updater   ~0040490

What is the status on this ?

Issue History

Date Modified Username Field Change
2011-03-14 15:38 mabri New Issue
2011-03-14 15:41 mabri Tag Attached: import
2011-04-04 20:25 mabri File Added: svgplugin-import-text-as-text.diff
2011-04-04 20:25 mabri File Added: import_text_test_CMYK.svg
2011-04-04 20:41 mabri Note Added: 0026003
2011-04-04 20:45 mabri Note Edited: 0026003
2011-04-04 20:47 mabri Note Edited: 0026003
2011-07-10 23:22 jghali Relationship added has duplicate 0010125
2011-08-10 23:15 Vladimir Savic Note Added: 0026705
2014-08-18 20:35 Kunda Summary svg plug-in doesn't import text as (editable) text => [PATCH] svg plug-in doesn't import text as (editable) text
2014-10-13 16:02 Kunda Tag Detached: import
2014-10-24 22:57 Kunda Patch => Yes
2016-04-26 01:04 Kunda Note Added: 0040490
2016-04-26 01:04 Kunda Tag Attached: #pending