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 - - + + + + + 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 - - - 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 - - - - - - - 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..4d4f5d3 100644 --- a/src/components/text.py +++ b/src/components/text.py @@ -1,25 +1,23 @@ -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 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,20 +42,41 @@ 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', + 'stroke', 'shadX', 'shadY', 'shadBlur' ]) self.centerXY() 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,14 +121,62 @@ 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() + 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)) + image.drawPath(path) + + 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 f76979c..13d3467 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,91 +82,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 5 - 20 - - - - - - - - - 0 - 0 - - - - Font Size - - - - - - - 1 - - - 500 - - - - - - - - - - - Text Color - - - - - - - - - - - 32 - 32 - - - - - - - - 32 - 32 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - @@ -186,7 +103,20 @@ - + + + + 0 + 0 + + + + + 100 + 16777215 + + + @@ -206,8 +136,14 @@ + + + 0 + 0 + + - Center + Center Text @@ -243,14 +179,14 @@ - + 0 0 - 80 + 50 16777215 @@ -271,6 +207,137 @@ + + + + + 0 + 0 + + + + Y + + + + + + + + 0 + 0 + + + + + 50 + 16777215 + + + + 999999999 + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Text Color + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 5 + 20 + + + + + + + + + 0 + 0 + + + + Font Size + + + + + + + + 0 + 0 + + + + + + + + + + 1 + + + 500 + + + @@ -288,7 +355,7 @@ - + 0 @@ -296,29 +363,284 @@ - Y + Font Style - + + + + Normal + + + + + Semi-Bold + + + + + Bold + + + + + Italic + + + + + Bold Italic + + + + + Faux Italic + + + + + Small Caps + + + + + + + + + + - + 0 0 - 80 + 0 16777215 - - 999999999 + + Qt::NoFocus + + + + + 0 + 0 + + + + Stroke + + + + + + + + 0 + 0 + + + + px + + + + + + + + 0 + 0 + + + + Stroke Color + + + + + + + + 0 + 0 + + + + + 0 + 16777215 + + + + Qt::NoFocus + + + + + + + + 0 + 0 + + + + + 32 + 32 + + + + + + + + 32 + 32 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + Shadow + + + + + + + + 0 + 0 + + + + Shadow Offset + + + + + + + + 0 + 0 + + + + -1000 + + + 1000 + + + -4 + + + + + + + + 0 + 0 + + + + -1000 + + + 1000 + + + 8 + + + + + + + + 0 + 0 + + + + Shadow Blur + + + + + + + + 0 + 0 + + + + 99.000000000000000 + + + 0.100000000000000 + + + 5.000000000000000 + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 40 + 20 + + + + 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()