/* For general Scribus (>=1.3.2) copyright and licensing information please refer to the COPYING file provided with the program. Following this notice may exist a copyright and/or license notice that predates the release of Scribus 1.3.2 for which a new license (GPL+exception) is in place. 02.01.2008: Joachim Neu - joachim_neu@web.de - http://www.joachim-neu.de */ #include "cmdstyle.h" #include "cmdutil.h" #include "qbuffer.h" #include "qpixmap.h" //Added by qt3to4: #include #include "scribuscore.h" #include "styles/paragraphstyle.h" #include "styles/charstyle.h" #include "stylemanager.h" /*! 02.01.2007 - 05.01.2007 : Joachim Neu : Create a paragraph style. Special thanks go to avox for helping me! */ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyObject* keywords) { char* keywordargs[] = { const_cast("name"), const_cast("linespacingmode"), const_cast("linespacing"), const_cast("alignment"), const_cast("leftmargin"), const_cast("rightmargin"), const_cast("gapbefore"), const_cast("gapafter"), const_cast("firstindent"), const_cast("hasdropcap"), const_cast("dropcaplines"), const_cast("dropcapoffset"), const_cast("charstyle"), NULL}; char *Name = const_cast(""), *CharStyle = const_cast(""); int LineSpacingMode = 0, Alignment = 0, DropCapLines = 2, HasDropCap = 0; double LineSpacing = 15.0, LeftMargin = 0.0, RightMargin = 0.0; double GapBefore = 0.0, GapAfter = 0.0, FirstIndent = 0.0, DropCapOffset = 0; if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiides", keywordargs, "utf-8", &Name, &LineSpacingMode, &LineSpacing, &Alignment, &LeftMargin, &RightMargin, &GapBefore, &GapAfter, &FirstIndent, &HasDropCap, &DropCapLines, &DropCapOffset, "utf-8", &CharStyle)) return NULL; if(!checkHaveDocument()) return NULL; if (Name == EMPTY_STRING) { PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty paragraph style name.","python error").toLocal8Bit().constData()); return NULL; } ParagraphStyle TmpParagraphStyle; TmpParagraphStyle.setName(Name); TmpParagraphStyle.setLineSpacingMode((ParagraphStyle::LineSpacingMode)LineSpacingMode); TmpParagraphStyle.setLineSpacing(LineSpacing); TmpParagraphStyle.setAlignment((ParagraphStyle::AlignmentType)Alignment); TmpParagraphStyle.setLeftMargin(LeftMargin); TmpParagraphStyle.setFirstIndent(FirstIndent); TmpParagraphStyle.setRightMargin(RightMargin); TmpParagraphStyle.setGapBefore(GapBefore); TmpParagraphStyle.setGapAfter(GapAfter); if(HasDropCap == 0) TmpParagraphStyle.setHasDropCap(false); else if(HasDropCap == 1) TmpParagraphStyle.setHasDropCap(true); else { PyErr_SetString(PyExc_ValueError, QObject::tr("hasdropcap has to be 0 or 1.","python error").toLocal8Bit().constData()); return NULL; } TmpParagraphStyle.setDropCapLines(DropCapLines); TmpParagraphStyle.setDropCapOffset(DropCapOffset); TmpParagraphStyle.charStyle().setParent(CharStyle); StyleSet TmpStyleSet; TmpStyleSet.create(TmpParagraphStyle); ScCore->primaryMainWindow()->doc->redefineStyles(TmpStyleSet, false); // PV - refresh the Style Manager window. // I thought that this can work but it doesn't: // ScCore->primaryMainWindow()->styleMgr()->reloadStyleView(); // So the brute force setDoc is called... ScCore->primaryMainWindow()->styleMgr()->setDoc(ScCore->primaryMainWindow()->doc); Py_RETURN_NONE; } /*! 03.01.2007 - 05.01.2007 : Joachim Neu : Create a char style. Special thanks go to avox for helping me! */ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject* keywords) { char* keywordargs[] = { const_cast("name"), const_cast("font"), const_cast("fontsize"), const_cast("features"), const_cast("fillcolor"), const_cast("fillshade"), const_cast("strokecolor"), const_cast("strokeshade"), const_cast("baselineoffset"), const_cast("shadowxoffset"), const_cast("shadowyoffset"), const_cast("outlinewidth"), const_cast("underlineoffset"), const_cast("underlinewidth"), const_cast("strikethruoffset"), const_cast("strikethruwidth"), const_cast("scaleh"), const_cast("scalev"), const_cast("tracking"), const_cast("language"), NULL}; char *Name = const_cast(""), *Font = const_cast("Times"), *Features = const_cast("inherit"), *FillColor = const_cast("Black"), *StrokeColor = const_cast("Black"), *Language = const_cast(""); double FontSize = 200, FillShade = 1, StrokeShade = 1, ScaleH = 1, ScaleV = 1, BaselineOffset = 0, ShadowXOffset = 0, ShadowYOffset = 0, OutlineWidth = 0, UnderlineOffset = 0, UnderlineWidth = 0, StrikethruOffset = 0, StrikethruWidth = 0, Tracking = 0; if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddes", keywordargs, "utf-8", &Name, "utf-8", &Font, &FontSize, "utf-8", &Features, "utf-8", &FillColor, &FillShade, "utf-8", &StrokeColor, &StrokeShade, &BaselineOffset, &ShadowXOffset, &ShadowYOffset, &OutlineWidth, &UnderlineOffset, &UnderlineWidth, &StrikethruOffset, &StrikethruWidth, &ScaleH, &ScaleV, &Tracking, "utf-8", &Language)) return NULL; if(!checkHaveDocument()) return NULL; if(Name == EMPTY_STRING) { PyErr_SetString(PyExc_ValueError, QObject::tr("Cannot have an empty char style name.","python error").toLocal8Bit().constData()); return NULL; } QStringList FeaturesList = QString(Features).split(QString(",")); CharStyle TmpCharStyle; TmpCharStyle.setName(Name); TmpCharStyle.setFont((*ScCore->primaryMainWindow()->doc->AllFonts)[QString(Font)]); TmpCharStyle.setFontSize(FontSize * 10); TmpCharStyle.setFeatures(FeaturesList); TmpCharStyle.setFillColor(QString(FillColor)); TmpCharStyle.setFillShade(FillShade * 100); TmpCharStyle.setStrokeColor(QString(StrokeColor)); TmpCharStyle.setStrokeShade(StrokeShade * 100); TmpCharStyle.setBaselineOffset(BaselineOffset); TmpCharStyle.setShadowXOffset(ShadowXOffset); TmpCharStyle.setShadowYOffset(ShadowYOffset); TmpCharStyle.setOutlineWidth(OutlineWidth); TmpCharStyle.setUnderlineOffset(UnderlineOffset); TmpCharStyle.setUnderlineWidth(UnderlineWidth); TmpCharStyle.setStrikethruOffset(StrikethruOffset); TmpCharStyle.setStrikethruWidth(StrikethruWidth); TmpCharStyle.setScaleH(ScaleH * 1000); TmpCharStyle.setScaleV(ScaleV * 1000); TmpCharStyle.setTracking(Tracking); TmpCharStyle.setLanguage(QString(Language)); StyleSet TmpStyleSet; TmpStyleSet.create(TmpCharStyle); ScCore->primaryMainWindow()->doc->redefineCharStyles(TmpStyleSet, false); // PV - refresh the Style Manager window. // I thought that this can work but it doesn't: // ScCore->primaryMainWindow()->styleMgr()->reloadStyleView(); // So the brute force setDoc is called... ScCore->primaryMainWindow()->styleMgr()->setDoc(ScCore->primaryMainWindow()->doc); Py_RETURN_NONE; } /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ void cmdstyledocwarnings() { QStringList s; s << scribus_createparagraphstyle__doc__ << scribus_createcharstyle__doc__; }