Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFontFamily Class Reference

The KoFontFamily class Abstract representation of a Weight/Width/Slant font family, as determined by KoFFWWSConverter. More...

#include <KoFontFamily.h>

+ Inheritance diagram for KoFontFamily:

Classes

struct  Private
 

Public Member Functions

QList< KoSvgText::FontFamilyAxisaxes () const
 
KoResourceSP clone () const override
 
bool colorBitmap () const
 Font has color bitmaps.
 
bool colorClrV0 () const
 Font has colrv0 layers.
 
bool colorClrV1 () const
 Font has colrv1 layers – doesn't yet work.
 
bool colorSVG () const
 Font is SVG.
 
bool isSerializable () const override
 
bool isVariable () const
 Font is variable.
 
 KoFontFamily (const KoFontFamily &rhs)
 
 KoFontFamily (const QString &filename)
 
 KoFontFamily (KoFontFamilyWWSRepresentation representation)
 
QDateTime lastModified () const
 
bool loadFromDevice (QIODevice *dev, KisResourcesInterfaceSP resourcesInterface) override
 
KoFontFamilyoperator= (const KoFontFamily &rhs)=delete
 
QPair< QString, QString > resourceType () const override
 
QList< KoSvgText::FontFamilyStyleInfostyles () const
 
QString translatedFontName (QStringList locales) const
 Return the translated name for a given locale...
 
QString typographicFamily () const
 Returns the typographic family name, if any.
 
void updateThumbnail () override
 updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.
 
 ~KoFontFamily ()
 
- Public Member Functions inherited from KoResource
bool active () const
 
void addMetaData (QString key, QVariant value)
 store the given key, value pair in the resource
 
virtual void clearSideLoadedResources ()
 
virtual QString defaultFileExtension () const
 
virtual QList< KoResourceLoadResultembeddedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
QString filename () const
 
QImage image () const
 
bool isDirty () const
 
virtual bool isEphemeral () const
 
 KoResource ()
 
 KoResource (const KoResource &rhs)
 
 KoResource (const QString &filename)
 
virtual QList< KoResourceLoadResultlinkedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
bool load (KisResourcesInterfaceSP resourcesInterface)
 
QString md5Sum (bool generateIfEmpty=true) const
 
QMap< QString, QVariant > metadata () const
 get a map with all the metadata
 
virtual QString name () const
 
KoResourceoperator= (const KoResource &rhs)=delete
 
bool permanent () const
 
virtual QList< int > requiredCanvasResources () const
 
QList< KoResourceLoadResultrequiredResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
int resourceId () const
 
bool save ()
 
virtual bool saveToDevice (QIODevice *dev) const
 
void setActive (bool active)
 
void setDirty (bool value)
 Mark the preset as modified but not saved.
 
void setFilename (const QString &filename)
 
void setImage (const QImage &image)
 
void setMD5Sum (const QString &md5sum)
 Set the md5sum of this resource. It must be in hex-encoded string format.
 
void setName (const QString &name)
 
void setPermanent (bool permanent)
 
void setResourceId (int id)
 
void setStorageLocation (const QString &location)
 
void setValid (bool valid)
 
void setVersion (int version)
 
virtual QList< KoResourceLoadResultsideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface) const
 
KoResourceSignature signature () const
 
QString storageLocation () const
 
QList< KoResourceLoadResulttakeSideLoadedResources (KisResourcesInterfaceSP globalResourcesInterface)
 
virtual QImage thumbnail () const
 thumbnail the thumbnail image to use in resource selectors
 
virtual QString thumbnailPath () const
 thumbnailPath returns the path to a separate thumbnail image, outside the actual resource file itself. If the path is relative, it is supposed start in the same location as the resource itself. If it's absolute, that is, it starts with "/", it is from the root of the storage.
 
bool valid () const
 
int version () const
 Get the version of the resource.
 
virtual ~KoResource ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 

Private Attributes

QScopedPointer< Privated
 

Additional Inherited Members

- Public Attributes inherited from KoResource
bool active {true}
 
QString filename
 
QImage image
 
QString md5sum
 
QMap< QString, QVariant > metadata
 
bool modified {false}
 
QString name
 
bool permanent {false}
 
int resourceId {-1}
 
QString storageLocation
 
bool valid {false}
 
int version {-1}
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 

Detailed Description

The KoFontFamily class Abstract representation of a Weight/Width/Slant font family, as determined by KoFFWWSConverter.

Definition at line 19 of file KoFontFamily.h.

Constructor & Destructor Documentation

◆ KoFontFamily() [1/3]

KoFontFamily::KoFontFamily ( KoFontFamilyWWSRepresentation representation)
explicit

Definition at line 93 of file KoFontFamily.cpp.

94 : KoResource(representation.fontFamilyName)
95 , d(new Private())
96
97{
98 setName(representation.fontFamilyName);
103
104 addMetaData(LAST_MODIFIED, representation.lastModified);
105
106 QMap<QString, QVariant> samples;
107 Q_FOREACH(const QString key, representation.sampleStrings.keys()) {
108 samples.insert(key, QVariant::fromValue(representation.sampleStrings.value(key)));
109 }
110 addMetaData(SAMPLE_STRING, samples);
111 QList<QVariant> supportedLanguages;
112 Q_FOREACH(const QLocale l, representation.supportedLanguages) {
113 QString val = l.bcp47Name();
114 val.replace("_", "-");
115 supportedLanguages.append(QVariant::fromValue(val));
116 }
117 addMetaData(SUPPORTED_LANGUAGES, supportedLanguages);
118
119 addMetaData(FONT_TYPE, representation.type);
120 addMetaData(IS_VARIABLE, representation.isVariable);
121 addMetaData(COLOR_BITMAP, representation.colorBitMap);
122 addMetaData(COLOR_CLRV0, representation.colorClrV0);
123 addMetaData(COLOR_CLRV1, representation.colorClrV1);
124 addMetaData(COLOR_SVG, representation.colorSVG);
125 QVariantHash axes;
126 Q_FOREACH(const QString key, representation.axes.keys()) {
127 axes.insert(key, QVariant::fromValue(representation.axes.value(key)));
128 }
130 QVariantList styles;
131 Q_FOREACH(const KoSvgText::FontFamilyStyleInfo style, representation.styles) {
132 styles.append(QVariant::fromValue(style));
133 }
135 setMD5Sum(KoMD5Generator::generateHash(representation.fontFamilyName.toUtf8()));
136 setValid(true);
137}
const QString SUPPORTED_LANGUAGES
const QString TYPOGRAPHIC_NAME
const QString COLOR_BITMAP
const QString LOCALIZED_TYPOGRAPHIC_STYLE
const QString COLOR_SVG
const QString LOCALIZED_TYPOGRAPHIC_NAME
const QString COLOR_CLRV0
const QString IS_VARIABLE
QMap< QString, QVariant > localeHashtoVariantMap(QHash< QLocale, QString > names)
const QString FONT_TYPE
const QString AXES
const QString LOCALIZED_FONT_FAMILY
const QString STYLES
const QString LAST_MODIFIED
const QString SAMPLE_STRING
const QString COLOR_CLRV1
QList< KoSvgText::FontFamilyAxis > axes() const
QList< KoSvgText::FontFamilyStyleInfo > styles() const
QScopedPointer< Private > d
static QString generateHash(const QString &filename)
generateHash reads the given file and generates a hex-encoded md5sum for the file.
QList< KoSvgText::FontFamilyStyleInfo > styles
QHash< QString, KoSvgText::FontFamilyAxis > axes
KoSvgText::FontFormatType type
QDateTime lastModified
Value of the most recently modified font family. Used for updates.
QHash< QLocale, QString > localizedTypographicStyles
QList< QLocale > supportedLanguages
sample string used to generate the preview;
QHash< QString, QString > sampleStrings
QHash< QLocale, QString > localizedTypographicFamily
QHash< QLocale, QString > localizedFontFamilyNames
void setValid(bool valid)
void setName(const QString &name)
void addMetaData(QString key, QVariant value)
store the given key, value pair in the resource
void setMD5Sum(const QString &md5sum)
Set the md5sum of this resource. It must be in hex-encoded string format.

References KoResource::addMetaData(), AXES, axes(), KoFontFamilyWWSRepresentation::axes, COLOR_BITMAP, COLOR_CLRV0, COLOR_CLRV1, COLOR_SVG, KoFontFamilyWWSRepresentation::colorBitMap, KoFontFamilyWWSRepresentation::colorClrV0, KoFontFamilyWWSRepresentation::colorClrV1, KoFontFamilyWWSRepresentation::colorSVG, FONT_TYPE, KoFontFamilyWWSRepresentation::fontFamilyName, KoMD5Generator::generateHash(), IS_VARIABLE, KoFontFamilyWWSRepresentation::isVariable, LAST_MODIFIED, KoFontFamilyWWSRepresentation::lastModified, localeHashtoVariantMap(), LOCALIZED_FONT_FAMILY, LOCALIZED_TYPOGRAPHIC_NAME, LOCALIZED_TYPOGRAPHIC_STYLE, KoFontFamilyWWSRepresentation::localizedFontFamilyNames, KoFontFamilyWWSRepresentation::localizedTypographicFamily, KoFontFamilyWWSRepresentation::localizedTypographicStyles, SAMPLE_STRING, KoFontFamilyWWSRepresentation::sampleStrings, KoResource::setMD5Sum(), KoResource::setName(), KoResource::setValid(), STYLES, styles(), KoFontFamilyWWSRepresentation::styles, SUPPORTED_LANGUAGES, KoFontFamilyWWSRepresentation::supportedLanguages, KoFontFamilyWWSRepresentation::type, TYPOGRAPHIC_NAME, and KoFontFamilyWWSRepresentation::typographicFamilyName.

◆ KoFontFamily() [2/3]

KoFontFamily::KoFontFamily ( const QString & filename)

◆ ~KoFontFamily()

KoFontFamily::~KoFontFamily ( )

Definition at line 146 of file KoFontFamily.cpp.

147{
148}

◆ KoFontFamily() [3/3]

KoFontFamily::KoFontFamily ( const KoFontFamily & rhs)

Definition at line 150 of file KoFontFamily.cpp.

151 : KoResource(QString())
152 , d(new Private(*rhs.d))
153{
154 setFilename(rhs.filename());
155 QMap<QString, QVariant> meta = metadata();
156 Q_FOREACH(const QString key, meta.keys()) {
157 addMetaData(key, meta.value(key));
158 }
159 setValid(true);
160}
void setFilename(const QString &filename)
QMap< QString, QVariant > metadata

References KoResource::addMetaData(), KoResource::filename, KoResource::metadata, KoResource::setFilename(), and KoResource::setValid().

Member Function Documentation

◆ axes()

QList< KoSvgText::FontFamilyAxis > KoFontFamily::axes ( ) const

Definition at line 249 of file KoFontFamily.cpp.

250{
251 QVariantHash axes = metadata().value(AXES).toHash();
253 Q_FOREACH(const QString key, axes.keys()) {
254 converted.append(axes.value(key).value<KoSvgText::FontFamilyAxis>());
255 }
256 return converted;
257}

References AXES, axes(), and KoResource::metadata.

◆ clone()

KoResourceSP KoFontFamily::clone ( ) const
overridevirtual

Implements KoResource.

Definition at line 162 of file KoFontFamily.cpp.

163{
164 return KoResourceSP(new KoFontFamily(*this));
165}
KoFontFamily(KoFontFamilyWWSRepresentation representation)
QSharedPointer< KoResource > KoResourceSP

References KoFontFamily().

◆ colorBitmap()

bool KoFontFamily::colorBitmap ( ) const

Font has color bitmaps.

Definition at line 229 of file KoFontFamily.cpp.

230{
231 return metadata().value(COLOR_BITMAP).toBool();
232}

References COLOR_BITMAP, and KoResource::metadata.

◆ colorClrV0()

bool KoFontFamily::colorClrV0 ( ) const

Font has colrv0 layers.

Definition at line 234 of file KoFontFamily.cpp.

235{
236 return metadata().value(COLOR_CLRV0).toBool();
237}

References COLOR_CLRV0, and KoResource::metadata.

◆ colorClrV1()

bool KoFontFamily::colorClrV1 ( ) const

Font has colrv1 layers – doesn't yet work.

Definition at line 239 of file KoFontFamily.cpp.

240{
241 return metadata().value(COLOR_CLRV1).toBool();
242}

References COLOR_CLRV1, and KoResource::metadata.

◆ colorSVG()

bool KoFontFamily::colorSVG ( ) const

Font is SVG.

Definition at line 244 of file KoFontFamily.cpp.

245{
246 return metadata().value(COLOR_SVG).toBool();
247}

References COLOR_SVG, and KoResource::metadata.

◆ isSerializable()

bool KoFontFamily::isSerializable ( ) const
overridevirtual

Serializable resource is the one which can be saved/loaded into a specific storage via saveToDevice()/loadFromDevice() methods. Some resources, like KisAbrBrush or KisPsdLayerStyle, are stored in specific libraries in "batches". Such resources cannot be saved individually. They are created by the corresponding factories.

In contrast to ephemeral resource, non-serializable resource will always have a correct md5Sum() and may be stored in the resources database.

Reimplemented from KoResource.

Definition at line 174 of file KoFontFamily.cpp.

175{
176 return false;
177}

◆ isVariable()

bool KoFontFamily::isVariable ( ) const

Font is variable.

Definition at line 224 of file KoFontFamily.cpp.

225{
226 return metadata().value(IS_VARIABLE).toBool();
227}

References IS_VARIABLE, and KoResource::metadata.

◆ lastModified()

QDateTime KoFontFamily::lastModified ( ) const

Definition at line 269 of file KoFontFamily.cpp.

270{
271 return metadata().value(LAST_MODIFIED).toDateTime();
272}

References LAST_MODIFIED, and KoResource::metadata.

◆ loadFromDevice()

bool KoFontFamily::loadFromDevice ( QIODevice * dev,
KisResourcesInterfaceSP resourcesInterface )
overridevirtual

Implements KoResource.

Definition at line 167 of file KoFontFamily.cpp.

168{
169 Q_UNUSED(dev)
170 Q_UNUSED(resourcesInterface);
171 return false;
172}

◆ operator=()

KoFontFamily & KoFontFamily::operator= ( const KoFontFamily & rhs)
delete

◆ resourceType()

QPair< QString, QString > KoFontFamily::resourceType ( ) const
overridevirtual
Returns
the resource type

Implements KoResource.

Definition at line 179 of file KoFontFamily.cpp.

180{
181 return QPair<QString, QString>(ResourceType::FontFamilies, "");
182}

References ResourceType::FontFamilies.

◆ styles()

QList< KoSvgText::FontFamilyStyleInfo > KoFontFamily::styles ( ) const

Definition at line 259 of file KoFontFamily.cpp.

260{
261 QVariantList styles = metadata().value(STYLES).toList();
263 Q_FOREACH(const QVariant val, styles) {
264 converted.append(val.value<KoSvgText::FontFamilyStyleInfo>());
265 }
266 return converted;
267}

References KoResource::metadata, STYLES, and styles().

◆ translatedFontName()

QString KoFontFamily::translatedFontName ( QStringList locales) const

Return the translated name for a given locale...

Definition at line 211 of file KoFontFamily.cpp.

212{
213 QMap<QString, QVariant> names = metadata().value(LOCALIZED_FONT_FAMILY).toMap();
214 QString name = filename();
215 Q_FOREACH(const QString locale, locales) {
216 if (names.keys().contains(locale)) {
217 name = names.value(locale).toString();
218 break;
219 }
220 }
221 return name;
222}
QString name

References KoResource::filename, LOCALIZED_FONT_FAMILY, KoResource::metadata, and KoResource::name.

◆ typographicFamily()

QString KoFontFamily::typographicFamily ( ) const

Returns the typographic family name, if any.

Definition at line 206 of file KoFontFamily.cpp.

207{
208 return metadata().value(TYPOGRAPHIC_NAME).toString();
209}

References KoResource::metadata, and TYPOGRAPHIC_NAME.

◆ updateThumbnail()

void KoFontFamily::updateThumbnail ( )
overridevirtual

updateThumbnail updates the thumbnail for this resource. Reimplement if your thumbnail is something else than the image set with setImage.

Reimplemented from KoResource.

Definition at line 184 of file KoFontFamily.cpp.

185{
186 QHash<QString, QVariant> samples = metadata().value(SAMPLE_STRING).toHash();
187 QMap<QString, QVariant> sampleSVG;
188 QMap<QString, QVariant> sampleSVGBbox;
189
190 Q_FOREACH (const QString key, samples.keys()) {
191 QString sample = samples.value(key).toString();
192 QRectF sampleBBox;
193 QString lang = key.startsWith("l_")? key.right(key.size() - 2): "";
194 sampleSVG.insert(key, QVariant::fromValue(generateSVG(sample, filename(), sampleBBox, lang)));
195 sampleSVGBbox.insert(key, QVariant::fromValue(sampleBBox));
196 }
197
198 addMetaData(SAMPLE_SVG, sampleSVG);
199 addMetaData(SAMPLE_BBOX, sampleSVGBbox);
200 const QString sample = samples.isEmpty()? "AaBbGg"
201 : samples.value("s_Latn", samples.values().first()).toString();
202 bool isColor = (metadata().value(COLOR_BITMAP).toBool() || metadata().value(COLOR_CLRV0).toBool());
203 setImage(generateImage(sample, filename(), isColor));
204}
const QString SAMPLE_SVG
QString generateSVG(const KoSvgTextShape *shape)
const QString SAMPLE_BBOX
QImage generateImage(const QString &sample, const QString &fontFamily, bool isColor)
void setImage(const QImage &image)

References KoResource::addMetaData(), COLOR_BITMAP, COLOR_CLRV0, KoResource::filename, generateImage(), generateSVG(), KoResource::metadata, SAMPLE_BBOX, SAMPLE_STRING, SAMPLE_SVG, and KoResource::setImage().

Member Data Documentation

◆ d

QScopedPointer<Private> KoFontFamily::d
private

Definition at line 62 of file KoFontFamily.h.


The documentation for this class was generated from the following files: