View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017349 | Scribus | Scripter | public | 2024-12-22 14:18 | 2024-12-26 11:04 |
Reporter | ybon | Assigned To | cbradney | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | resolved | Resolution | fixed | ||
Product Version | 1.7.0.svn | ||||
Fixed in Version | 1.7.0.svn | ||||
Summary | 0017349: Expose char style background color in python API | ||||
Description | Another blind attempt to contribute. Seems to be working for me, but certainly far from perfect! Thanks for reviewing :) | ||||
Tags | No tags attached. | ||||
Patch | No | ||||
|
bgcolor.diff (3,400 bytes)
Index: scribus/plugins/scriptplugin/cmdstyle.cpp =================================================================== --- scribus/plugins/scriptplugin/cmdstyle.cpp (revision 26490) +++ scribus/plugins/scriptplugin/cmdstyle.cpp (working copy) @@ -174,6 +174,7 @@ const_cast<char*>("fillshade"), const_cast<char*>("strokecolor"), const_cast<char*>("strokeshade"), + const_cast<char*>("bgcolor"), const_cast<char*>("baselineoffset"), const_cast<char*>("shadowxoffset"), const_cast<char*>("shadowyoffset"), @@ -202,6 +203,7 @@ PyESString font; PyESString features; PyESString fillColor; + PyESString bgColor; PyESString fontFeatures; PyESString strokeColor; PyESString language; @@ -214,9 +216,9 @@ double strikethruOffset = dbl_min, strikethruWidth = dbl_min; double tracking = dbl_min; - if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesddddddddddddeses", keywordargs, + if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|esdesesdesdsdddddddddddeses", keywordargs, "utf-8", name.ptr(), "utf-8", font.ptr(), &fontSize, "utf-8", features.ptr(), - "utf-8", fillColor.ptr(), &fillShade, "utf-8", strokeColor.ptr(), &strokeShade, &baselineOffset, &shadowXOffset, + "utf-8", fillColor.ptr(), &fillShade, "utf-8", strokeColor.ptr(), &strokeShade, bgColor.ptr(), &baselineOffset, &shadowXOffset, &shadowYOffset, &outlineWidth, &underlineOffset, &underlineWidth, &strikethruOffset, &strikethruWidth, &scaleH, &scaleV, &tracking, "utf-8", language.ptr(), "utf-8", fontFeatures.ptr())) return nullptr; @@ -240,6 +242,7 @@ const ColorList& docColors = currentDoc->PageColors; QString qFillColor(fillColor.c_str()); QString qStrokeColor(strokeColor.defaulted("Black")); + QString qBgColor(bgColor.c_str()); if (!qFillColor.isEmpty()) { if ((qFillColor != CommonStrings::None) && (!docColors.contains(qFillColor))) @@ -256,6 +259,14 @@ return nullptr; } } + if (!qBgColor.isEmpty()) + { + if ((qBgColor != CommonStrings::None) && (!docColors.contains(qBgColor))) + { + PyErr_SetString(PyExc_ValueError, QObject::tr("Specified background color is not available in document.", "python error").toLocal8Bit().constData()); + return nullptr; + } + } if (fillShade >= 0) fillShade = qMax(0.0, qMin(fillShade, 1.0)); @@ -277,6 +288,8 @@ tmpCharStyle.setFeatures(featuresList); if (!qFillColor.isEmpty()) tmpCharStyle.setFillColor(qFillColor); + if (!qBgColor.isEmpty()) + tmpCharStyle.setBackColor(qBgColor); if (fillShade >= 0) tmpCharStyle.setFillShade(fillShade * 100); if (!qStrokeColor.isEmpty()) Index: scribus/plugins/scriptplugin/cmdstyle.h =================================================================== --- scribus/plugins/scriptplugin/cmdstyle.h (revision 26490) +++ scribus/plugins/scriptplugin/cmdstyle.h (working copy) @@ -75,6 +75,7 @@ -> smallcaps\n\n\ \"fillcolor\" [optional], \"fillshade\" [optional] -> specify fill options\n\n\ \"strokecolor\" [optional], \"strokeshade\" [optional] -> specify stroke options\n\n\ +\"bgcolor\" [optional] -> specify background color\n\n\ baselineoffset [optional] -> offset of the baseline\n\n\ shadowxoffset [optional], shadowyoffset [optional] -> offset of the shadow if used\n\n\ outlinewidth [optional] -> width of the outline if used\n\n\ |
|
Useful, thank you. |
|
Sample code for use in the scripter from ybon tested working: MARGIN = 10 COL_WIDTH = 90 COL_HEIGHT = 277 newDocument(PAPER_A4_MM,(MARGIN, MARGIN, MARGIN, MARGIN),PORTRAIT,1,UNIT_MILLIMETERS,PAGE_2,0,0) setDocType(FACINGPAGES, FIRSTPAGERIGHT) CHAR_STYLES = {"STYLE1":{"font": "Arial Regular", "fontsize":9.0,"tracking": 150}, "STYLE2":{"font": "Arial Regular","fontsize":9.0,"tracking": 150,"fillcolor": "White","bgcolor": "Cyan"}} PARAGRAPH_STYLES = {"STYLE1":{"charstyle":"STYLE1","linespacing":17.0,"linespacingmode":0}} for cname, coptions in CHAR_STYLES.items(): createCharStyle(cname, **coptions) for pname, poptions in PARAGRAPH_STYLES.items(): createParagraphStyle(pname, **poptions) frame = createText(MARGIN, MARGIN, COL_WIDTH, COL_HEIGHT) setFirstLineOffset(FLOP_LINESPACING, frame) selectObject(frame) text = "test foobar" setParagraphStyle("STYLE1") insertText(text + "\r", -1, frame) selectText(5, 6, frame) setCharacterStyle("STYLE2") deselectAll() |
Date Modified | Username | Field | Change |
---|---|---|---|
2024-12-22 14:18 | ybon | New Issue | |
2024-12-22 14:18 | ybon | File Added: bgcolor.diff | |
2024-12-23 15:20 | luzpaz | Note Added: 0051771 | |
2024-12-26 10:48 | cbradney | Note Added: 0051783 | |
2024-12-26 11:00 | cbradney | Note Edited: 0051783 | |
2024-12-26 11:01 | cbradney | Note Edited: 0051783 | |
2024-12-26 11:04 | cbradney | Assigned To | => cbradney |
2024-12-26 11:04 | cbradney | Status | new => resolved |
2024-12-26 11:04 | cbradney | Resolution | open => fixed |
2024-12-26 11:04 | cbradney | Fixed in Version | => 1.7.0.svn |