From 998f74149553ac7a9e27d7c85cebceda2ef32c64 Mon Sep 17 00:00:00 2001 From: tassaron Date: Sun, 6 Aug 2017 21:52:44 -0400 Subject: added stroke and font style options to Text component --- src/component.py | 4 +- src/components/image.ui | 336 +++++++++++++++++----------------- src/components/original.ui | 2 +- src/components/text.py | 65 +++++-- src/components/text.ui | 439 +++++++++++++++++++++++++++++++++++++-------- 5 files changed, 593 insertions(+), 253 deletions(-) (limited to 'src') diff --git a/src/component.py b/src/component.py index 5b38473..5b6f9a7 100644 --- a/src/component.py +++ b/src/component.py @@ -198,7 +198,7 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): try: preset = self.savePreset() except Exception as e: - preset = '%s occured while saving preset' % str(e) + preset = '%s occurred while saving preset' % str(e) return '%s\n%s\n%s' % ( self.__class__.name, str(self.__class__.version), preset ) @@ -275,7 +275,7 @@ class Component(QtCore.QObject, metaclass=ComponentMetaclass): Call super().widget(*args) to create the component widget which also auto-connects any common widgets (e.g., checkBoxes) to self.update(). Then in a subclass connect special actions - (e.g., pushButtons to select a file/colour) and initialize + (e.g., pushButtons to select a file) and initialize ''' self.parent = parent self.settings = parent.settings diff --git a/src/components/image.ui b/src/components/image.ui index e549ed0..1837b64 100644 --- a/src/components/image.ui +++ b/src/components/image.ui @@ -178,177 +178,177 @@ - - - - - - - - Stretch - - - false - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 5 - 20 - - - - - - - - Mirror - - - - - - - Rotate - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - QAbstractSpinBox::UpDownArrows - - - ° - - - 0 - - - 359 - - - 0 - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 20 - - - - - - - - - 0 - 0 - - - - Scale - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - QAbstractSpinBox::UpDownArrows - - - % - - - 10 - - - 400 - - - 100 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - Color - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + + + + Stretch + + + false + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + Mirror + + + + + + + Rotate + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::UpDownArrows + + + ° + + + 0 + + + 359 + + + 0 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + 0 + 0 + + + + Scale + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::UpDownArrows + + + % + + + 10 + + + 400 + + + 100 + + + + - - - QAbstractSpinBox::UpDownArrows - - - % - - - 0 - - - 999 - - - 1 - - - 100 - - + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Color + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + QAbstractSpinBox::UpDownArrows + + + % + + + 0 + + + 999 + + + 1 + + + 100 + + + + diff --git a/src/components/original.ui b/src/components/original.ui index 8fa9b2b..a4d5119 100644 --- a/src/components/original.ui +++ b/src/components/original.ui @@ -6,7 +6,7 @@ 0 0 - 633 + 586 178 diff --git a/src/components/text.py b/src/components/text.py index c3f3bdc..f88f373 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -4,22 +4,20 @@ from PyQt5 import QtGui, QtCore, QtWidgets import os from component import Component -from toolkit.frame import FramePainter +from toolkit.frame import FramePainter, PaintColor class Component(Component): name = 'Title Text' version = '1.0.1' - def __init__(self, *args): - super().__init__(*args) - self.titleFont = QFont() - def widget(self, *args): super().widget(*args) self.textColor = (255, 255, 255) + self.strokeColor = (0, 0, 0) self.title = 'Text' self.alignment = 1 + self.titleFont = QFont() self.fontSize = self.height / 13.5 self.page.comboBox_textAlign.addItem("Left") @@ -28,6 +26,7 @@ class Component(Component): self.page.comboBox_textAlign.setCurrentIndex(int(self.alignment)) self.page.lineEdit_textColor.setText('%s,%s,%s' % self.textColor) + self.page.lineEdit_strokeColor.setText('%s,%s,%s' % self.strokeColor) self.page.spinBox_fontSize.setValue(int(self.fontSize)) self.page.lineEdit_title.setText(self.title) @@ -43,8 +42,16 @@ class Component(Component): 'fontSize': self.page.spinBox_fontSize, 'xPosition': self.page.spinBox_xTextAlign, 'yPosition': self.page.spinBox_yTextAlign, + 'fontStyle': self.page.comboBox_fontStyle, + 'stroke': self.page.spinBox_stroke, + 'strokeColor': self.page.lineEdit_strokeColor, + 'shadow': self.page.checkBox_shadow, + 'shadX': self.page.spinBox_shadX, + 'shadY': self.page.spinBox_shadY, + 'shadBlur': self.page.spinBox_shadBlur, }, colorWidgets={ 'textColor': self.page.pushButton_textColor, + 'strokeColor': self.page.pushButton_strokeColor, }, relativeWidgets=[ 'xPosition', 'yPosition', 'fontSize', ]) @@ -52,11 +59,23 @@ class Component(Component): def update(self): self.titleFont = self.page.fontComboBox_titleFont.currentFont() + if self.page.checkBox_shadow.isChecked(): + self.page.label_shadX.setHidden(False) + self.page.spinBox_shadX.setHidden(False) + self.page.spinBox_shadY.setHidden(False) + self.page.label_shadBlur.setHidden(False) + self.page.spinBox_shadBlur.setHidden(False) + else: + self.page.label_shadX.setHidden(True) + self.page.spinBox_shadX.setHidden(True) + self.page.spinBox_shadY.setHidden(True) + self.page.label_shadBlur.setHidden(True) + self.page.spinBox_shadBlur.setHidden(True) super().update() def centerXY(self): self.setRelativeWidget('xPosition', 0.5) - self.setRelativeWidget('yPosition', 0.5) + self.setRelativeWidget('yPosition', 0.521) def getXY(self): '''Returns true x, y after considering alignment settings''' @@ -101,13 +120,39 @@ class Component(Component): return self.addText(self.width, self.height) def addText(self, width, height): + font = self.titleFont + font.setPixelSize(self.fontSize) + font.setStyle(QFont.StyleNormal) + font.setWeight(QFont.Normal) + font.setCapitalization(QFont.MixedCase) + if self.fontStyle == 1: + font.setWeight(QFont.DemiBold) + if self.fontStyle == 2: + font.setWeight(QFont.Bold) + elif self.fontStyle == 3: + font.setStyle(QFont.StyleItalic) + elif self.fontStyle == 4: + font.setWeight(QFont.Bold) + font.setStyle(QFont.StyleItalic) + elif self.fontStyle == 5: + font.setStyle(QFont.StyleOblique) + elif self.fontStyle == 6: + font.setCapitalization(QFont.SmallCaps) + image = FramePainter(width, height) - self.titleFont.setPixelSize(self.fontSize) - image.setFont(self.titleFont) - image.setPen(self.textColor) x, y = self.getXY() + if self.stroke > 0: + outliner = QtGui.QPainterPathStroker() + outliner.setWidth(self.stroke) + path = QtGui.QPainterPath() + path.addText(x, y, font, self.title) + path = outliner.createStroke(path) + image.setBrush(PaintColor(*self.strokeColor)) + image.drawPath(path) + + image.setFont(font) + image.setPen(self.textColor) image.drawText(x, y, self.title) - return image.finalize() def commandHelp(self): diff --git a/src/components/text.ui b/src/components/text.ui index f76979c..5a7e831 100644 --- a/src/components/text.ui +++ b/src/components/text.ui @@ -16,6 +16,12 @@ + + 6 + + + QLayout::SetDefaultConstraint + 4 @@ -31,7 +37,7 @@ - + 0 0 @@ -47,14 +53,10 @@ - - - - - + 0 0 @@ -67,7 +69,7 @@ - + 0 0 @@ -80,8 +82,44 @@ + + + + + + 0 + - + + + + 0 + 0 + + + + Text Layout + + + + + + + + 0 + 0 + + + + + 100 + 16777215 + + + + + + Qt::Horizontal @@ -97,7 +135,36 @@ - + + + + 0 + 0 + + + + Center Text + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + 0 @@ -105,36 +172,104 @@ - Font Size + X - + + + + 0 + 0 + + + + + 50 + 16777215 + + + + + 0 + 0 + + - 1 + 0 - 500 + 999999999 + + + 0 + + + + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + 999999999 - + + + + 0 + 0 + + + + + 16777215 + 16777215 + + Text Color - - - + + + 0 + 0 + + 32 @@ -153,27 +288,23 @@ - + Qt::Horizontal + + QSizePolicy::Fixed + - 40 + 5 20 - - - - - - 0 - - + 0 @@ -181,15 +312,34 @@ - Text Layout + Font Size - + + + + 0 + 0 + + + + + + + + + + 1 + + + 500 + + - + Qt::Horizontal @@ -205,30 +355,82 @@ - + + + + 0 + 0 + + - Center + Font Style - - - Qt::Horizontal - - - QSizePolicy::Fixed + + + + Normal + + + + + Semi-Bold + + + + + Bold + + + + + Italic + + + + + Bold Italic + + + + + Faux Italic + + + + + Small Caps + + + + + + + + + + + + + 0 + 0 + - + - 5 - 20 + 0 + 16777215 - + + Qt::NoFocus + + - + 0 @@ -236,59 +438,112 @@ - X + Stroke - + - + + 0 + 0 + + + + px + + + + + + + + 0 + 0 + + + + Stroke Color + + + + + + + 0 0 - 80 + 0 16777215 - + + Qt::NoFocus + + + + + + + + 0 + 0 + + + - 0 - 0 + 32 + 32 - - 0 - - - 999999999 + + - - 0 + + + 32 + 32 + - + Qt::Horizontal - - QSizePolicy::Fixed - - 5 + 40 20 + + + + - + + + + 0 + 0 + + + + Shadow + + + + + 0 @@ -296,29 +551,69 @@ - Y + Shadow Offset - + 0 0 - - - 80 - 16777215 - + + + + + + + 0 + 0 + - - 999999999 + + + + + + + 0 + 0 + + + + Shadow Blur + + + + + 0 + 0 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + -- cgit v1.2.3 From 060a7dc2d263c0fd0e36e162943b8946df937bbd Mon Sep 17 00:00:00 2001 From: tassaron Date: Mon, 7 Aug 2017 21:03:01 -0400 Subject: dropshadow option for Text component --- src/components/text.py | 16 ++++++++++++++-- src/components/text.ui | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/components/text.py b/src/components/text.py index f88f373..c50c812 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -1,4 +1,4 @@ -from PIL import Image, ImageDraw +from PIL import ImageEnhance, ImageFilter, ImageChops from PyQt5.QtGui import QColor, QFont from PyQt5 import QtGui, QtCore, QtWidgets import os @@ -153,7 +153,19 @@ class Component(Component): image.setFont(font) image.setPen(self.textColor) image.drawText(x, y, self.title) - return image.finalize() + + # turn QImage into Pillow frame + frame = image.finalize() + if self.shadow: + shadImg = ImageEnhance.Contrast(frame).enhance(0.0) + shadImg = shadImg.filter(ImageFilter.GaussianBlur(self.shadBlur)) + shadImg = ImageChops.offset(shadImg, self.shadX, self.shadY) + shadImg.paste(frame, box=(0, 0), mask=frame) + frame = shadImg + + return frame + + def commandHelp(self): print('Enter a string to use as centred white text:') diff --git a/src/components/text.ui b/src/components/text.ui index 5a7e831..13d3467 100644 --- a/src/components/text.ui +++ b/src/components/text.ui @@ -563,6 +563,15 @@ 0 + + -1000 + + + 1000 + + + -4 + @@ -573,6 +582,15 @@ 0 + + -1000 + + + 1000 + + + 8 + @@ -596,6 +614,15 @@ 0 + + 99.000000000000000 + + + 0.100000000000000 + + + 5.000000000000000 + -- cgit v1.2.3 From 354637d34c201b9389b9085889275d6850873d08 Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 8 Aug 2017 05:57:19 -0400 Subject: relative stroke px size & no Qt pen on stroke --- src/components/text.py | 3 ++- src/toolkit/frame.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/text.py b/src/components/text.py index c50c812..46fb001 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -53,7 +53,7 @@ class Component(Component): 'textColor': self.page.pushButton_textColor, 'strokeColor': self.page.pushButton_strokeColor, }, relativeWidgets=[ - 'xPosition', 'yPosition', 'fontSize', + 'xPosition', 'yPosition', 'fontSize', 'stroke' ]) self.centerXY() @@ -147,6 +147,7 @@ class Component(Component): path = QtGui.QPainterPath() path.addText(x, y, font, self.title) path = outliner.createStroke(path) + image.setPen(QtCore.Qt.NoPen) image.setBrush(PaintColor(*self.strokeColor)) image.drawPath(path) diff --git a/src/toolkit/frame.py b/src/toolkit/frame.py index c007188..7e83d58 100644 --- a/src/toolkit/frame.py +++ b/src/toolkit/frame.py @@ -21,8 +21,11 @@ class FramePainter(QtGui.QPainter): self.image = QtGui.QImage(ImageQt(image)) super().__init__(self.image) - def setPen(self, RgbTuple): - super().setPen(PaintColor(*RgbTuple)) + def setPen(self, penStyle): + if type(penStyle) is tuple: + super().setPen(PaintColor(*penStyle)) + else: + super().setPen(penStyle) def finalize(self): self.end() -- cgit v1.2.3 From 4d0daa4336432948ba6543d4becaaa42425ecafd Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 8 Aug 2017 06:03:14 -0400 Subject: relative dropshadow --- src/components/text.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/components/text.py b/src/components/text.py index 46fb001..f6bd17d 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -53,7 +53,8 @@ class Component(Component): 'textColor': self.page.pushButton_textColor, 'strokeColor': self.page.pushButton_strokeColor, }, relativeWidgets=[ - 'xPosition', 'yPosition', 'fontSize', 'stroke' + 'xPosition', 'yPosition', 'fontSize', + 'stroke', 'shadX', 'shadY', 'shadBlur' ]) self.centerXY() -- cgit v1.2.3 From 3ed84e1c3edba46fe8990544ef7e58fe8e3dd901 Mon Sep 17 00:00:00 2001 From: tassaron Date: Tue, 8 Aug 2017 20:53:51 -0400 Subject: fixed incorrect outline for small-caps --- src/components/text.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/components/text.py b/src/components/text.py index f6bd17d..4d4f5d3 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -146,7 +146,18 @@ class Component(Component): outliner = QtGui.QPainterPathStroker() outliner.setWidth(self.stroke) path = QtGui.QPainterPath() - path.addText(x, y, font, self.title) + if self.fontStyle == 6: + # PathStroker ignores smallcaps so we need this weird hack + path.addText(x, y, font, self.title[0]) + fm = QtGui.QFontMetrics(font) + newX = x + fm.width(self.title[0]) + strokeFont = self.page.fontComboBox_titleFont.currentFont() + strokeFont.setCapitalization(QFont.SmallCaps) + strokeFont.setPixelSize(int((self.fontSize / 7) * 5)) + strokeFont.setLetterSpacing(QFont.PercentageSpacing, 139) + path.addText(newX, y, strokeFont, self.title[1:]) + else: + path.addText(x, y, font, self.title) path = outliner.createStroke(path) image.setPen(QtCore.Qt.NoPen) image.setBrush(PaintColor(*self.strokeColor)) @@ -167,8 +178,6 @@ class Component(Component): return frame - - def commandHelp(self): print('Enter a string to use as centred white text:') print(' "title=User Error"') -- cgit v1.2.3