aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Ben Wagner <bungeman@google.com>2017-01-25 11:15:50 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-26 22:21:34 +0000
commit25272300c308335f2d87c2a70e249965b268bcb0 (patch)
treedb2d539a1b22e9db81918a40e6a05a9da47bea31 /src
parentbbeb5730e7365d0952d3dbb5846001708b9517a3 (diff)
Implement getFamilyName for stream fonts on Linux.
When SkFontMgr_fontconfig and SkFontMgr_FontConfigInterface create a typeface from data they do not store the default font name and getFamilyName will return the empty string. All of the code to handle this properly now exists, it just needs to be hooked up. BUG=skia:1508 Change-Id: I75f2a598a5451babb4a9ceb5e9a9e9d3daa41d60 Reviewed-on: https://skia-review.googlesource.com/7506 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/ports/SkFontConfigTypeface.h16
-rw-r--r--src/ports/SkFontMgr_FontConfigInterface.cpp9
-rw-r--r--src/ports/SkFontMgr_fontconfig.cpp19
3 files changed, 26 insertions, 18 deletions
diff --git a/src/ports/SkFontConfigTypeface.h b/src/ports/SkFontConfigTypeface.h
index 0da78aed87..e27fbb3d85 100644
--- a/src/ports/SkFontConfigTypeface.h
+++ b/src/ports/SkFontConfigTypeface.h
@@ -22,16 +22,16 @@ class SkTypeface_FCI : public SkTypeface_FreeType {
public:
static SkTypeface_FCI* Create(sk_sp<SkFontConfigInterface> fci,
const SkFontConfigInterface::FontIdentity& fi,
- const SkString& familyName,
+ SkString familyName,
const SkFontStyle& style)
{
- return new SkTypeface_FCI(std::move(fci), fi, familyName, style);
+ return new SkTypeface_FCI(std::move(fci), fi, std::move(familyName), style);
}
static SkTypeface_FCI* Create(std::unique_ptr<SkFontData> data,
- SkFontStyle style, bool isFixedPitch)
+ SkString familyName, SkFontStyle style, bool isFixedPitch)
{
- return new SkTypeface_FCI(std::move(data), style, isFixedPitch);
+ return new SkTypeface_FCI(std::move(data), std::move(familyName), style, isFixedPitch);
}
const SkFontConfigInterface::FontIdentity& getIdentity() const {
@@ -41,16 +41,18 @@ public:
protected:
SkTypeface_FCI(sk_sp<SkFontConfigInterface> fci,
const SkFontConfigInterface::FontIdentity& fi,
- const SkString& familyName,
+ SkString familyName,
const SkFontStyle& style)
: INHERITED(style, false)
, fFCI(std::move(fci))
, fIdentity(fi)
- , fFamilyName(familyName)
+ , fFamilyName(std::move(familyName))
, fFontData(nullptr) {}
- SkTypeface_FCI(std::unique_ptr<SkFontData> data, SkFontStyle style, bool isFixedPitch)
+ SkTypeface_FCI(std::unique_ptr<SkFontData> data,
+ SkString familyName, SkFontStyle style, bool isFixedPitch)
: INHERITED(style, isFixedPitch)
+ , fFamilyName(std::move(familyName))
, fFontData(std::move(data))
{
SkASSERT(fFontData);
diff --git a/src/ports/SkFontMgr_FontConfigInterface.cpp b/src/ports/SkFontMgr_FontConfigInterface.cpp
index 4795ba5974..81c4868e5d 100644
--- a/src/ports/SkFontMgr_FontConfigInterface.cpp
+++ b/src/ports/SkFontMgr_FontConfigInterface.cpp
@@ -211,14 +211,15 @@ protected:
}
// TODO should the caller give us the style or should we get it from freetype?
+ SkString name;
SkFontStyle style;
bool isFixedPitch = false;
- if (!fScanner.scanFont(stream.get(), 0, nullptr, &style, &isFixedPitch, nullptr)) {
+ if (!fScanner.scanFont(stream.get(), 0, &name, &style, &isFixedPitch, nullptr)) {
return nullptr;
}
auto fontData = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
+ return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
}
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
@@ -251,7 +252,7 @@ protected:
params.getCollectionIndex(),
axisValues.get(),
axisDefinitions.count());
- return SkTypeface_FCI::Create(std::move(fontData), style, isFixedPitch);
+ return SkTypeface_FCI::Create(std::move(fontData), std::move(name), style, isFixedPitch);
}
SkTypeface* onCreateFromFile(const char path[], int ttcIndex) const override {
@@ -284,7 +285,7 @@ protected:
// Check if a typeface with this FontIdentity is already in the FontIdentity cache.
face = fTFCache.findByProcAndRef(find_by_FontIdentity, &identity);
if (!face) {
- face = SkTypeface_FCI::Create(fFCI, identity, outFamilyName, outStyle);
+ face = SkTypeface_FCI::Create(fFCI, identity, std::move(outFamilyName), outStyle);
// Add this FontIdentity to the FontIdentity cache.
fTFCache.add(face);
}
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 0fe352a9cd..63d720b390 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -406,13 +406,15 @@ static void fcpattern_from_skfontstyle(SkFontStyle style, FcPattern* pattern) {
class SkTypeface_stream : public SkTypeface_FreeType {
public:
/** @param data takes ownership of the font data.*/
- SkTypeface_stream(std::unique_ptr<SkFontData> data, const SkFontStyle& style, bool fixedWidth)
+ SkTypeface_stream(std::unique_ptr<SkFontData> data,
+ SkString familyName, const SkFontStyle& style, bool fixedWidth)
: INHERITED(style, fixedWidth)
+ , fFamilyName(std::move(familyName))
, fData(std::move(data))
{ }
void onGetFamilyName(SkString* familyName) const override {
- familyName->reset();
+ *familyName = fFamilyName;
}
void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
@@ -429,6 +431,7 @@ public:
}
private:
+ SkString fFamilyName;
const std::unique_ptr<const SkFontData> fData;
typedef SkTypeface_FreeType INHERITED;
@@ -885,14 +888,15 @@ protected:
return nullptr;
}
+ SkString name;
SkFontStyle style;
bool isFixedWidth = false;
- if (!fScanner.scanFont(stream.get(), ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
+ if (!fScanner.scanFont(stream.get(), ttcIndex, &name, &style, &isFixedWidth, nullptr)) {
return nullptr;
}
auto data = skstd::make_unique<SkFontData>(std::move(stream), ttcIndex, nullptr, 0);
- return new SkTypeface_stream(std::move(data), style, isFixedWidth);
+ return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedWidth);
}
SkTypeface* onCreateFromStream(SkStreamAsset* s, const FontParameters& params) const override {
@@ -915,7 +919,7 @@ protected:
auto data = skstd::make_unique<SkFontData>(std::move(stream), params.getCollectionIndex(),
axisValues.get(), axisDefinitions.count());
- return new SkTypeface_stream(std::move(data), style, isFixedPitch);
+ return new SkTypeface_stream(std::move(data), std::move(name), style, isFixedPitch);
}
SkTypeface* onCreateFromData(SkData* data, int ttcIndex) const override {
@@ -934,13 +938,14 @@ protected:
}
const int ttcIndex = fontData->getIndex();
+ SkString name;
SkFontStyle style;
bool isFixedWidth = false;
- if (!fScanner.scanFont(stream, ttcIndex, nullptr, &style, &isFixedWidth, nullptr)) {
+ if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedWidth, nullptr)) {
return nullptr;
}
- return new SkTypeface_stream(std::move(fontData), style, isFixedWidth);
+ return new SkTypeface_stream(std::move(fontData), std::move(name), style, isFixedWidth);
}
SkTypeface* onLegacyCreateTypeface(const char familyName[], SkFontStyle style) const override {