Skip to content

Commit

Permalink
Making fontStyle and fixedPitch fields "virtual"
Browse files Browse the repository at this point in the history
Change-Id: Ia8483ec76d887bdf384db4a534e9f0ec1effa49c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/923296
Reviewed-by: Ben Wagner <[email protected]>
Commit-Queue: Julia Lavrova <[email protected]>
  • Loading branch information
Rusino authored and SkCQ committed Nov 21, 2024
1 parent 0586d90 commit d1e1390
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
14 changes: 8 additions & 6 deletions include/core/SkTypeface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ typedef uint32_t SkFontTableTag;
class SK_API SkTypeface : public SkWeakRefCnt {
public:
/** Returns the typeface's intrinsic style attributes. */
SkFontStyle fontStyle() const {
return fStyle;
}
SkFontStyle fontStyle() const;

/** Returns true if style() has the kBold bit set. */
bool isBold() const { return fStyle.weight() >= SkFontStyle::kSemiBold_Weight; }
bool isBold() const;

/** Returns true if style() has the kItalic bit set. */
bool isItalic() const { return fStyle.slant() != SkFontStyle::kUpright_Slant; }
bool isItalic() const;

/** Returns true if the typeface claims to be fixed-pitch.
* This is a style bit, advance widths may vary even if this returns true.
*/
bool isFixedPitch() const { return fIsFixedPitch; }
bool isFixedPitch() const;

/** Copy into 'coordinates' (allocated by the caller) the design variation coordinates.
*
Expand Down Expand Up @@ -363,6 +361,10 @@ class SK_API SkTypeface : public SkWeakRefCnt {
/** Sets the font style. If used, must be called in the constructor. */
void setFontStyle(SkFontStyle style) { fStyle = style; }

virtual SkFontStyle onGetFontStyle() const; // TODO: = 0;

virtual bool onGetFixedPitch() const; // TODO: = 0;

// Must return a valid scaler context. It can not return nullptr.
virtual std::unique_ptr<SkScalerContext> onCreateScalerContext(const SkScalerContextEffects&,
const SkDescriptor*) const = 0;
Expand Down
24 changes: 24 additions & 0 deletions src/core/SkTypeface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,30 @@ int SkTypeface::onGetResourceName(SkString* resourceName) const {
return 0;
}

SkFontStyle SkTypeface::fontStyle() const {
return this->onGetFontStyle();
}

SkFontStyle SkTypeface::onGetFontStyle() const {
return fStyle;
}

bool SkTypeface::isBold() const {
return this->onGetFontStyle().weight() >= SkFontStyle::kSemiBold_Weight;
}

bool SkTypeface::isItalic() const {
return this->onGetFontStyle().slant() != SkFontStyle::kUpright_Slant;
}

bool SkTypeface::isFixedPitch() const {
return this->onGetFixedPitch();
}

bool SkTypeface::onGetFixedPitch() const {
return fIsFixedPitch;
}

void SkTypeface::getGlyphToUnicodeMap(SkUnichar* dst) const {
sk_bzero(dst, sizeof(SkUnichar) * this->countGlyphs());
}
Expand Down
8 changes: 8 additions & 0 deletions src/ports/SkTypeface_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ int SkTypeface_proxy::onGetVariationDesignParameters(SkFontParameters::Variation
return fProxy->onGetVariationDesignParameters(parameters, parameterCount);
}

SkFontStyle SkTypeface_proxy::onGetFontStyle() const {
return fProxy->onGetFontStyle();
}

bool SkTypeface_proxy::onGetFixedPitch() const {
return fProxy->onGetFixedPitch();
}

void SkTypeface_proxy::onGetFamilyName(SkString* familyName) const {
fProxy->onGetFamilyName(familyName);
}
Expand Down
2 changes: 2 additions & 0 deletions src/ports/SkTypeface_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class SkTypeface_proxy : public SkTypeface {
int coordinateCount) const override;
int onGetVariationDesignParameters(SkFontParameters::Variation::Axis parameters[],
int parameterCount) const override;
SkFontStyle onGetFontStyle() const override;
bool onGetFixedPitch() const override;
void onGetFamilyName(SkString* familyName) const override;
bool onGetPostScriptName(SkString* postScriptName) const override;
int onGetResourceName(SkString* resourceName) const override;
Expand Down

0 comments on commit d1e1390

Please sign in to comment.