r17498 by fschmid - Updates to the PDF-Importer for the handling of OCG groups.
scribus-commit
scribus-commit at lists.scribus.net
Sun May 6 08:40:10 UTC 2012
Author: fschmid
Date: Sun May 6 08:40:10 2012
New Revision: 17498
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17498
Log:
Updates to the PDF-Importer for the handling of OCG groups.
Modified:
trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17498&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp Sun May 6 08:40:10 2012
@@ -278,9 +278,9 @@
bool PdfPlug::convert(QString fn)
{
- bool firstLayer = true;
bool firstPg = true;
int currentLayer = m_Doc->activeLayer();
+ int baseLayer = m_Doc->activeLayer();
importedColors.clear();
if(progressDialog)
{
@@ -322,6 +322,8 @@
hasOcg = ocg->hasOCGs();
if (hasOcg)
{
+
+ QStringList ocgNames;
Array *order = ocg->getOrderArray();
if (order)
{
@@ -336,9 +338,30 @@
if (ref.isRef())
{
OptionalContentGroup *oc = ocg->findOcgByRef(ref.getRef());
- ocgGroups.prepend(oc);
+ QString ocgName = UnicodeParsedString(oc->getName());
+ if (!ocgNames.contains(ocgName))
+ {
+ ocgGroups.prepend(oc);
+ ocgNames.append(ocgName);
+ }
}
ref.free();
+ }
+ else
+ {
+ GooList *ocgs;
+ int i;
+ ocgs = ocg->getOCGs ();
+ for (i = 0; i < ocgs->getLength (); ++i)
+ {
+ OptionalContentGroup *oc = (OptionalContentGroup *)ocgs->get(i);
+ QString ocgName = UnicodeParsedString(oc->getName());
+ if (!ocgNames.contains(ocgName))
+ {
+ ocgGroups.prepend(oc);
+ ocgNames.append(ocgName);
+ }
+ }
}
}
}
@@ -350,7 +373,12 @@
for (i = 0; i < ocgs->getLength (); ++i)
{
OptionalContentGroup *oc = (OptionalContentGroup *)ocgs->get(i);
- ocgGroups.prepend(oc);
+ QString ocgName = UnicodeParsedString(oc->getName());
+ if (!ocgNames.contains(ocgName))
+ {
+ ocgGroups.prepend(oc);
+ ocgNames.append(ocgName);
+ }
}
}
}
@@ -362,19 +390,18 @@
int rotate = pdfDoc->getPageRotate(firstPage);
if (importerFlags & LoadSavePlugin::lfCreateDoc)
{
+// POPPLER_VERSION appeared in 0.19.0 first
+#ifdef POPPLER_VERSION
if (hasOcg)
{
+ QString actL = m_Doc->activeLayerName();
for (int a = 0; a < ocgGroups.count(); a++)
{
OptionalContentGroup *oc = ocgGroups[a];
- if (firstLayer)
- {
- m_Doc->changeLayerName(m_Doc->activeLayer(), UnicodeParsedString(oc->getName()));
- currentLayer = m_Doc->activeLayer();
- firstLayer = false;
- }
+ if (actL != UnicodeParsedString(oc->getName()))
+ currentLayer = m_Doc->addLayer(UnicodeParsedString(oc->getName()), false);
else
- currentLayer = m_Doc->addLayer(UnicodeParsedString(oc->getName()), false);
+ currentLayer = m_Doc->layerIDFromName(UnicodeParsedString(oc->getName()));
// POPPLER_VERSION appeared in 0.19.0 first
#ifdef POPPLER_VERSION
if ((oc->getViewState() == OptionalContentGroup::ocUsageOn) || (oc->getViewState() == OptionalContentGroup::ocUsageUnset))
@@ -401,6 +428,7 @@
}
dev->layersSetByOCG = true;
}
+#endif
Object info;
pdfDoc->getDocInfo(&info);
if (info.isDict())
@@ -436,6 +464,7 @@
info.free();
for (int pp = 0; pp < lastPage; pp++)
{
+ m_Doc->setActiveLayer(baseLayer);
if (firstPg)
firstPg = false;
else
@@ -453,12 +482,13 @@
for (int a = 0; a < ocgGroups.count(); a++)
{
OptionalContentGroup *oc = ocgGroups[a];
- m_Doc->setActiveLayer(UnicodeParsedString(oc->getName()));
- currentLayer = m_Doc->activeLayer();
+ // m_Doc->setActiveLayer(UnicodeParsedString(oc->getName()));
+ // currentLayer = m_Doc->activeLayer();
oc->setState(OptionalContentGroup::On);
- pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing);
- oc->setState(OptionalContentGroup::Off);
+ // pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing);
+ // oc->setState(OptionalContentGroup::Off);
}
+ pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing);
}
else
pdfDoc->displayPage(dev, pp + 1, hDPI, vDPI, rotate, useMediaBox, crop, printing);
Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17498&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 Sun May 6 08:40:10 2012
@@ -1375,12 +1375,68 @@
delete image;
}
+void SlaOutputDev::beginMarkedContent(char *name, Object *dictRef)
+{
+ mContent mSte;
+ mSte.name = QString(name);
+ mSte.ocgName = "";
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ {
+ if (dictRef->isNull())
+ return;
+ Object dictObj;
+ Dict *dict;
+ Object dictType;
+ OCGs *contentConfig = catalog->getOptContentConfig();
+ OptionalContentGroup *oc;
+ if (dictRef->isRef())
+ {
+ oc = contentConfig->findOcgByRef(dictRef->getRef());
+ if (oc)
+ {
+// qDebug() << "Begin OCG Content (Ref) with Name " << QString(name) << "Layer" << UnicodeParsedString(oc->getName());
+ m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
+ mSte.ocgName = UnicodeParsedString(oc->getName());
+ }
+ }
+ else
+ {
+ dictRef->fetch(xref, &dictObj);
+ if (!dictObj.isDict())
+ {
+ dictObj.free();
+ return;
+ }
+ dict = dictObj.getDict();
+ dict->lookup("Type", &dictType);
+ if (dictType.isName("OCG"))
+ {
+ oc = contentConfig->findOcgByRef(dictRef->getRef());
+ if (oc)
+ {
+// qDebug() << "Begin OCG Content with Name " << UnicodeParsedString(oc->getName());
+ m_doc->setActiveLayer(UnicodeParsedString(oc->getName()));
+ mSte.ocgName = UnicodeParsedString(oc->getName());
+ }
+ }
+ dictType.free();
+ dictObj.free();
+ }
+ }
+ m_mcStack.push(mSte);
+}
+
void SlaOutputDev::beginMarkedContent(char *name, Dict *properties)
{
// qDebug() << "Begin Marked Content with Name " << QString(name);
+ QString nam = QString(name);
+ mContent mSte;
+ mSte.name = nam;
+ mSte.ocgName = "";
+ m_mcStack.push(mSte);
if (importerFlags & LoadSavePlugin::lfCreateDoc)
{
- if (QString(name) == "Layer") // Handle Adobe Illustrator Layer command
+ if (nam == "Layer") // Handle Adobe Illustrator Layer command
{
if (layersSetByOCG)
return;
@@ -1447,6 +1503,24 @@
void SlaOutputDev::endMarkedContent(GfxState *state)
{
// qDebug() << "End Marked Content";
+ if (m_mcStack.count() > 0)
+ {
+ mContent mSte = m_mcStack.pop();
+ if (importerFlags & LoadSavePlugin::lfCreateDoc)
+ {
+ if (mSte.name == "OC")
+ {
+ for (ScLayers::iterator it = m_doc->Layers.begin(); it != m_doc->Layers.end(); ++it)
+ {
+ if (it->Name == mSte.ocgName)
+ {
+ m_doc->setActiveLayer(mSte.ocgName);
+ return;
+ }
+ }
+ }
+ }
+ }
}
void SlaOutputDev::markPoint(char *name)
@@ -2461,3 +2535,40 @@
gElements.maskName = maskName;
m_groupStack.push(gElements);
}
+
+QString SlaOutputDev::UnicodeParsedString(GooString *s1)
+{
+ if ( !s1 || s1->getLength() == 0 )
+ return QString();
+ GBool isUnicode;
+ int i;
+ Unicode u;
+ QString result;
+ if ((s1->getChar(0) & 0xff) == 0xfe && (s1->getLength() > 1 && (s1->getChar(1) & 0xff) == 0xff))
+ {
+ isUnicode = gTrue;
+ i = 2;
+ result.reserve((s1->getLength() - 2) / 2);
+ }
+ else
+ {
+ isUnicode = gFalse;
+ i = 0;
+ result.reserve(s1->getLength());
+ }
+ while (i < s1->getLength())
+ {
+ if (isUnicode)
+ {
+ u = ((s1->getChar(i) & 0xff) << 8) | (s1->getChar(i+1) & 0xff);
+ i += 2;
+ }
+ else
+ {
+ u = s1->getChar(i) & 0xff;
+ ++i;
+ }
+ result += QChar( u );
+ }
+ return result;
+}
Modified: trunk/Scribus/scribus/plugins/import/pdf/slaoutput.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17498&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 Sun May 6 08:40:10 2012
@@ -83,6 +83,7 @@
virtual GBool useTilingPatternFill() { return gTrue; }
virtual GBool useShadedFills(int type) { return type <= 7; }
virtual GBool useFillColorStop() { return gTrue; }
+ virtual GBool useDrawForm() { return gFalse; }
virtual void startPage(int, GfxState *);
virtual void endPage();
// grapics state
@@ -93,7 +94,6 @@
virtual void stroke(GfxState *state);
virtual void fill(GfxState *state);
virtual void eoFill(GfxState *state);
- virtual void clipToStrokePath(GfxState *state) { qDebug() << "clip to stroke path"; }
virtual GBool tilingPatternFill(GfxState *state, Catalog *cat, Object *str, double *pmat, int paintType, Dict *resDict,
double *mat, double *bbox, int x0, int y0, int x1, int y1, double xStep, double yStep);
virtual GBool axialShadedFill(GfxState *state, GfxAxialShading *shading, double tMin, double tMax);
@@ -105,6 +105,7 @@
//----- path clipping
virtual void clip(GfxState *state);
virtual void eoClip(GfxState *state);
+ virtual void clipToStrokePath(GfxState * /*state*/) { qDebug() << "Clip to StrokePath"; }
virtual GBool deviceHasTextClip(GfxState *state) { return gFalse; }
// If current colorspace is pattern,
@@ -125,6 +126,7 @@
//----- grouping operators
virtual void beginMarkedContent(char *name, Dict *properties);
+ virtual void beginMarkedContent(char *name, Object *dictRef);
virtual void endMarkedContent(GfxState *state);
virtual void markPoint(char *name);
virtual void markPoint(char *name, Dict *properties);
@@ -165,6 +167,10 @@
virtual void endType3Char(GfxState * /*state*/);
virtual void type3D0(GfxState * /*state*/, double /*wx*/, double /*wy*/);
virtual void type3D1(GfxState * /*state*/, double /*wx*/, double /*wy*/, double /*llx*/, double /*lly*/, double /*urx*/, double /*ury*/);
+ //----- form XObjects
+ virtual void drawForm(Ref /*id*/) { qDebug() << "Draw Form"; }
+ //----- links
+ virtual void processLink(AnnotLink * /*link*/) { qDebug() << "Draw Link"; }
bool layersSetByOCG;
private:
@@ -174,6 +180,7 @@
int getBlendMode(GfxState *state);
void applyMask(PageItem *ite);
void pushGroup(QString maskName = "", GBool forSoftMask = gFalse, GBool alpha = gFalse, bool inverted = false);
+ QString UnicodeParsedString(GooString *s1);
bool pathIsClosed;
QString CurrColorFill;
QString CurrColorStroke;
@@ -217,6 +224,12 @@
bool colored;
};
QMap<QString, F3GlyphEntry> m_Font_Pattern_Map;
+ struct mContent
+ {
+ QString name;
+ QString ocgName;
+ };
+ QStack<mContent> m_mcStack;
int grStackDepth;
int layerNum;
int currentLayer;
More information about the scribus-commit
mailing list