Browse Source

added text+ a screenshot

work in progress to set the initial position of text depending of his size.

added a doc folder and a screenshot for futur documentation usages

Signed-off-by: tuxun <tuxun@g4m1ngpc.tuxun.fr>
tuxun 2 years ago
parent
commit
40df986f02
4 changed files with 69 additions and 9 deletions
  1. BIN
      doc/capture8mars2019.png
  2. 56 6
      svgview.cpp
  3. 2 0
      svgview.h
  4. 11 3
      svgviewer.pro.user

BIN
doc/capture8mars2019.png


+ 56 - 6
svgview.cpp

@@ -237,6 +237,8 @@ void SvgView::ajouter_forme(QStringList toadd, QGraphicsScene *s)
     int pathcount=0;
 
     QList<Forme*> pth;//={0};
+    QList<QGraphicsTextItem*> txt;//={0};
+    int txtcount=0;
     QXmlStreamReader xml;
     xml.addData(toadd.join(""));
     while (!xml.atEnd()) {
@@ -351,13 +353,13 @@ void SvgView::ajouter_forme(QStringList toadd, QGraphicsScene *s)
                 //pth++;
             }
             else if(xml.name()=="g")
-            {              qDebug()<<"svgview:g not shown yet";
+            {              qDebug()<<"svgview:g not shown yet\n";
             }
             else if(xml.name()=="line")
-            {              qDebug()<<"svgview:line not shown yet";
+            {              qDebug()<<"svgview:line not shown yet\n";
             }
             else if(xml.name()=="path")
-            {              qDebug()<<"svgview:WIP";
+            {              qDebug()<<"svgview:WIP\n";
 
                 qDebug()<<"path style:"<<xml.attributes().value("style");
               //  style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:0.1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
@@ -420,14 +422,50 @@ QString pathcommand="";
 
             }  else if(xml.name()=="image")
             {
-                qDebug()<<"svgview:image not shown yet";
+                qDebug()<<"svgview:image not shown yet\n";
+            }else if(xml.name()=="text")
+            {
+               qDebug()<<"TEXT:\n";
+//                qDebug()<<xml.attributes().value("style").toString()<<endl;
+                QString  style=xml.attributes().value("style").toString();
+
+                int  pos3=style.indexOf("font-size:");
+                int  pos4=style.indexOf("px;line-height");
+
+                qDebug()<<style.mid(pos3+10,pos4-pos3-10);
+                this->serifFont= QFont("Sans-serif", style.mid(pos3+10,pos4-pos3-10).toFloat(), QFont::Normal);
+
+//                qDebug()<<xml.attributes().value("style").toString()<<endl;
+            }else if(xml.name()=="tspan")
+            {txtcount++;
+                qDebug()<<"tspan (from TEXT!):\n";
+               // qDebug()<<xml.attributes().value("style").toString()<<endl;
+                QString  style=xml.attributes().value("style").toString();
+                QFontMetrics fm(this->serifFont);
+                 int textWidthInPixels = fm.horizontalAdvance("How many pixels wide is this text?");
+                 int textHeightInPixels = fm.height();
+              //  qDebug()<<xml.readElementText();
+                QGraphicsTextItem *tmptxt=new QGraphicsTextItem("");
+tmptxt->setPos(QPointF(xml.attributes().value("x").toFloat()-fm.width('0')/2,xml.attributes().value("y").toFloat()-fm.height()/2));
+                  tmptxt->setFont(this->serifFont);
+//tmptxt->setTextWidth(1.41111112);
+
+
+tmptxt->setDefaultTextColor(QColor(Qt::red));
+tmptxt->setPlainText(xml.readElementText());
+txt<<tmptxt;
+              }else
+            {
+                qDebug()<<xml.name()<<"not shown yet(TODOWIP/TEXT)\n";
             }
         }
     }
     if (xml.hasError()) {
         qDebug()<<xml.errorString();
     }
-    for (int i=0; i < pathcount; i++)
+    int i=0;
+    int j=0;
+    for (i; i < pathcount; i++)
     {
         //!this->scene()->addPath(pth[i].getpath(),
         //!                    QPen (Qt::darkRed, 1, Qt::SolidLine, Qt::SquareCap, Qt::SvgMiterJoin));
@@ -437,6 +475,18 @@ QString pathcommand="";
         // this->pathList.append(pth[i]);
 
     }
+    for (j; j < txtcount; j++)
+    {
+        //!this->scene()->addPath(pth[i].getpath(),
+        //!                    QPen (Qt::darkRed, 1, Qt::SolidLine, Qt::SquareCap, Qt::SvgMiterJoin));
+        s->addItem(txt[j]);
+        //  std::cout<<"render"<<pth[i]->getcomputedstring().join("\n").toStdString()<<std::endl;
+
+        // this->pathList.append(pth[i]);
+
+    }
+    qDebug()<<i<<" qgraphictextitem and "<<j<< "forme added";
+
     // this->scene()->update();
     qDebug("svgview: end of xml processing");
     return;
@@ -447,7 +497,7 @@ QString pathcommand="";
     //!int pathcount=-1;
 
     bool makenew=false;
-    int i=0,j=0;
+    i=0;j=0;
     int point_count=toadd.size();
     // QGraphicsPathItem *Qpath=new QGraphicsPathItem();
     QLocale cl(QLocale::system());

+ 2 - 0
svgview.h

@@ -78,6 +78,8 @@ protected:
     void dropEvent(QDropEvent *event);
     void mousePressEvent(QMouseEvent *event);
 private:
+    QFont serifFont;
+
     RendererType m_renderer;
     bool simplepathview;
     QList<Forme*> pathList;

+ 11 - 3
svgviewer.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.8.1, 2019-03-03T16:39:50. -->
+<!-- Written by QtCreator 4.8.1, 2019-03-08T05:30:36. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>
@@ -59,6 +59,14 @@
     <value type="QString">-fno-delayed-template-parsing</value>
    </valuelist>
    <value type="bool" key="ClangCodeModel.UseGlobalConfig">true</value>
+   <value type="bool" key="ClangTools.BuildBeforeAnalysis">false</value>
+   <value type="QString" key="ClangTools.DiagnosticConfig">Builtin.TidyAndClazy</value>
+   <valuelist type="QVariantList" key="ClangTools.SelectedDirs">
+    <value type="QString">D:/codicoda/qtCut/svg4cnceditor/svgviewer.pro</value>
+   </valuelist>
+   <valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
+   <valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
+   <value type="bool" key="ClangTools.UseGlobalSettings">true</value>
   </valuemap>
  </data>
  <data>
@@ -67,7 +75,7 @@
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.12.1 MinGW 64-bit</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.12.1 MinGW 64-bit</value>
    <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5121.win64_mingw73_kit</value>
-   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
+   <value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
    <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
    <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
    <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@@ -308,7 +316,7 @@
     <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
     <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
     <value type="QString" key="RunConfiguration.WorkingDirectory"></value>
-    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/codicoda/qtCut/build-svgviewer-Desktop_Qt_5_12_1_MinGW_64_bit-Debug</value>
+    <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/codicoda/qtCut/build-svgviewer-Desktop_Qt_5_12_1_MinGW_64_bit-Release</value>
    </valuemap>
    <value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
   </valuemap>