Update Viewer for SkFont overrides.

Change-Id: I18871dd6db647b24db08a3e92e0470c5baa5850c
Reviewed-on: https://skia-review.googlesource.com/c/186082
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2019-01-23 10:34:59 -05:00 committed by Skia Commit-Bot
parent 9dc532dd13
commit 9613e45775
2 changed files with 161 additions and 105 deletions

View File

@ -355,7 +355,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
this->updateTitle();
fWindow->inval();
});
fCommands.addCommand('H', "Paint", "Hinting mode", [this]() {
fCommands.addCommand('H', "Font", "Hinting mode", [this]() {
if (!fFontOverrides.fHinting) {
fFontOverrides.fHinting = true;
fFont.setHinting(kNo_SkFontHinting);
@ -380,45 +380,45 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
fWindow->inval();
});
fCommands.addCommand('A', "Paint", "Antialias Mode", [this]() {
if (!(fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag)) {
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fFlags |= SkPaint::kAntiAlias_Flag;
if (!fPaintOverrides.fAntiAlias) {
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fAntiAlias = true;
fPaint.setAntiAlias(false);
gSkUseAnalyticAA = gSkForceAnalyticAA = false;
gSkUseDeltaAA = gSkForceDeltaAA = false;
} else {
fPaint.setAntiAlias(true);
switch (fPaintOverrides.fAntiAlias) {
switch (fPaintOverrides.fAntiAliasState) {
case SkPaintFields::AntiAliasState::Alias:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Normal;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::Normal;
gSkUseAnalyticAA = gSkForceAnalyticAA = false;
gSkUseDeltaAA = gSkForceDeltaAA = false;
break;
case SkPaintFields::AntiAliasState::Normal:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAEnabled;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::AnalyticAAEnabled;
gSkUseAnalyticAA = true;
gSkForceAnalyticAA = false;
gSkUseDeltaAA = gSkForceDeltaAA = false;
break;
case SkPaintFields::AntiAliasState::AnalyticAAEnabled:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::AnalyticAAForced;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::AnalyticAAForced;
gSkUseAnalyticAA = gSkForceAnalyticAA = true;
gSkUseDeltaAA = gSkForceDeltaAA = false;
break;
case SkPaintFields::AntiAliasState::AnalyticAAForced:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAEnabled;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::DeltaAAEnabled;
gSkUseAnalyticAA = gSkForceAnalyticAA = false;
gSkUseDeltaAA = true;
gSkForceDeltaAA = false;
break;
case SkPaintFields::AntiAliasState::DeltaAAEnabled:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::DeltaAAForced;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::DeltaAAForced;
gSkUseAnalyticAA = gSkForceAnalyticAA = false;
gSkUseDeltaAA = gSkForceDeltaAA = true;
break;
case SkPaintFields::AntiAliasState::DeltaAAForced:
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fFlags &= ~SkPaint::kAntiAlias_Flag;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fAntiAlias = false;
gSkUseAnalyticAA = fPaintOverrides.fOriginalSkUseAnalyticAA;
gSkForceAnalyticAA = fPaintOverrides.fOriginalSkForceAnalyticAA;
gSkUseDeltaAA = fPaintOverrides.fOriginalSkUseDeltaAA;
@ -438,7 +438,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
this->updateTitle();
fWindow->inval();
});
fCommands.addCommand('L', "Paint", "Subpixel Antialias Mode", [this]() {
fCommands.addCommand('L', "Font", "Subpixel Antialias Mode", [this]() {
if (!fFontOverrides.fEdging) {
fFontOverrides.fEdging = true;
fFont.setEdging(SkFont::Edging::kAlias);
@ -459,7 +459,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
this->updateTitle();
fWindow->inval();
});
fCommands.addCommand('S', "Paint", "Subpixel Position Mode", [this]() {
fCommands.addCommand('S', "Font", "Subpixel Position Mode", [this]() {
if (!fFontOverrides.fSubpixel) {
fFontOverrides.fSubpixel = true;
fFont.setSubpixel(false);
@ -699,26 +699,48 @@ void Viewer::updateTitle() {
}
SkPaintTitleUpdater paintTitle(&title);
auto paintFlag = [this, &paintTitle](SkPaint::Flags flag, bool (SkPaint::* isFlag)() const,
auto paintFlag = [this, &paintTitle](bool SkPaintFields::* flag,
bool (SkPaint::* isFlag)() const,
const char* on, const char* off)
{
if (fPaintOverrides.fFlags & flag) {
if (fPaintOverrides.*flag) {
paintTitle.append((fPaint.*isFlag)() ? on : off);
}
};
paintFlag(SkPaint::kAntiAlias_Flag, &SkPaint::isAntiAlias, "Antialias", "Alias");
paintFlag(SkPaint::kDither_Flag, &SkPaint::isDither, "DITHER", "No Dither");
#if 0
paintFlag(SkPaint::kFakeBoldText_Flag, &SkPaint::isFakeBoldText, "Fake Bold", "No Fake Bold");
paintFlag(SkPaint::kLinearText_Flag, &SkPaint::isLinearText, "Linear Text", "Non-Linear Text");
paintFlag(SkPaint::kSubpixelText_Flag, &SkPaint::isSubpixelText, "Subpixel Text", "Pixel Text");
paintFlag(SkPaint::kLCDRenderText_Flag, &SkPaint::isLCDRenderText, "LCD", "lcd");
paintFlag(SkPaint::kEmbeddedBitmapText_Flag, &SkPaint::isEmbeddedBitmapText,
"Bitmap Text", "No Bitmap Text");
paintFlag(SkPaint::kAutoHinting_Flag, &SkPaint::isAutohinted,
auto fontFlag = [this, &paintTitle](bool SkFontFields::* flag, bool (SkFont::* isFlag)() const,
const char* on, const char* off)
{
if (fFontOverrides.*flag) {
paintTitle.append((fFont.*isFlag)() ? on : off);
}
};
paintFlag(&SkPaintFields::fAntiAlias, &SkPaint::isAntiAlias, "Antialias", "Alias");
paintFlag(&SkPaintFields::fDither, &SkPaint::isDither, "DITHER", "No Dither");
fontFlag(&SkFontFields::fForceAutoHinting, &SkFont::isForceAutoHinting,
"Force Autohint", "No Force Autohint");
#endif
fontFlag(&SkFontFields::fEmbolden, &SkFont::isEmbolden, "Fake Bold", "No Fake Bold");
fontFlag(&SkFontFields::fLinearMetrics, &SkFont::isLinearMetrics,
"Linear Metrics", "Non-Linear Metrics");
fontFlag(&SkFontFields::fEmbeddedBitmaps, &SkFont::isEmbeddedBitmaps,
"Bitmap Text", "No Bitmap Text");
fontFlag(&SkFontFields::fSubpixel, &SkFont::isSubpixel, "Subpixel Text", "Pixel Text");
if (fFontOverrides.fEdging) {
switch (fFont.getEdging()) {
case SkFont::Edging::kAlias:
paintTitle.append("Alias Text");
break;
case SkFont::Edging::kAntiAlias:
paintTitle.append("Antialias Text");
break;
case SkFont::Edging::kSubpixelAntiAlias:
paintTitle.append("Subpixel Antialias Text");
break;
}
}
if (fFontOverrides.fHinting) {
switch (fFont.getHinting()) {
@ -1050,39 +1072,35 @@ public:
if (fFontOverrides->fHinting) {
font->writable()->setHinting(fFont->getHinting());
}
#if 0
if (fFontOverrides->fFlags & SkPaint::kAntiAlias_Flag) {
paint->writable()->setAntiAlias(fPaint->isAntiAlias());
if (fFontOverrides->fEdging) {
font->writable()->setEdging(fFont->getEdging());
}
if (fFontOverrides->fFlags & SkPaint::kFakeBoldText_Flag) {
paint->writable()->setFakeBoldText(fPaint->isFakeBoldText());
if (fFontOverrides->fEmbolden) {
font->writable()->setEmbolden(fFont->isEmbolden());
}
if (fFontOverrides->fFlags & SkPaint::kLinearText_Flag) {
paint->writable()->setLinearText(fPaint->isLinearText());
if (fFontOverrides->fLinearMetrics) {
font->writable()->setLinearMetrics(fFont->isLinearMetrics());
}
if (fFontOverrides->fFlags & SkPaint::kSubpixelText_Flag) {
paint->writable()->setSubpixelText(fPaint->isSubpixelText());
if (fFontOverrides->fSubpixel) {
font->writable()->setSubpixel(fFont->isSubpixel());
}
if (fFontOverrides->fFlags & SkPaint::kLCDRenderText_Flag) {
paint->writable()->setLCDRenderText(fPaint->isLCDRenderText());
if (fFontOverrides->fEmbeddedBitmaps) {
font->writable()->setEmbeddedBitmaps(fFont->isEmbeddedBitmaps());
}
if (fFontOverrides->fFlags & SkPaint::kEmbeddedBitmapText_Flag) {
paint->writable()->setEmbeddedBitmapText(fPaint->isEmbeddedBitmapText());
if (fFontOverrides->fForceAutoHinting) {
font->writable()->setForceAutoHinting(fFont->isForceAutoHinting());
}
if (fFontOverrides->fFlags & SkPaint::kAutoHinting_Flag) {
paint->writable()->setAutohinted(fPaint->isAutohinted());
}
#endif
return true;
}
bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type) const override {
if (*paint == nullptr) {
return true;
}
if (fPaintOverrides->fFlags & SkPaint::kAntiAlias_Flag) {
if (fPaintOverrides->fAntiAlias) {
paint->writable()->setAntiAlias(fPaint->isAntiAlias());
}
if (fPaintOverrides->fFlags & SkPaint::kDither_Flag) {
if (fPaintOverrides->fDither) {
paint->writable()->setDither(fPaint->isDither());
}
return true;
@ -1627,27 +1645,9 @@ void Viewer::drawImGui() {
}
if (ImGui::CollapsingHeader("Paint")) {
int hintingIdx = 0;
if (fFontOverrides.fHinting) {
hintingIdx = static_cast<unsigned>(fFont.getHinting()) + 1;
}
if (ImGui::Combo("Hinting", &hintingIdx,
"Default\0None\0Slight\0Normal\0Full\0\0"))
{
if (hintingIdx == 0) {
fFontOverrides.fHinting = false;
fFont.setHinting(kNo_SkFontHinting);
} else {
fFontOverrides.fHinting = true;
SkFontHinting hinting = SkTo<SkFontHinting>(hintingIdx - 1);
fFont.setHinting(hinting);
}
paramsChanged = true;
}
int aliasIdx = 0;
if (fPaintOverrides.fFlags & SkPaint::kAntiAlias_Flag) {
aliasIdx = SkTo<int>(fPaintOverrides.fAntiAlias) + 1;
if (fPaintOverrides.fAntiAlias) {
aliasIdx = SkTo<int>(fPaintOverrides.fAntiAliasState) + 1;
}
if (ImGui::Combo("Anti-Alias", &aliasIdx,
"Default\0Alias\0Normal\0AnalyticAAEnabled\0AnalyticAAForced\0"
@ -1658,13 +1658,13 @@ void Viewer::drawImGui() {
gSkUseDeltaAA = fPaintOverrides.fOriginalSkUseDeltaAA;
gSkForceDeltaAA = fPaintOverrides.fOriginalSkForceDeltaAA;
if (aliasIdx == 0) {
fPaintOverrides.fAntiAlias = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fFlags &= ~SkPaint::kAntiAlias_Flag;
fPaintOverrides.fAntiAliasState = SkPaintFields::AntiAliasState::Alias;
fPaintOverrides.fAntiAlias = false;
} else {
fPaintOverrides.fFlags |= SkPaint::kAntiAlias_Flag;
fPaintOverrides.fAntiAlias =SkTo<SkPaintFields::AntiAliasState>(aliasIdx-1);
fPaintOverrides.fAntiAlias = true;
fPaintOverrides.fAntiAliasState = SkTo<SkPaintFields::AntiAliasState>(aliasIdx-1);
fPaint.setAntiAlias(aliasIdx > 1);
switch (fPaintOverrides.fAntiAlias) {
switch (fPaintOverrides.fAntiAliasState) {
case SkPaintFields::AntiAliasState::Alias:
break;
case SkPaintFields::AntiAliasState::Normal:
@ -1693,19 +1693,19 @@ void Viewer::drawImGui() {
}
auto paintFlag = [this, &paramsChanged](const char* label, const char* items,
SkPaint::Flags flag,
bool SkPaintFields::* flag,
bool (SkPaint::* isFlag)() const,
void (SkPaint::* setFlag)(bool) )
{
int itemIndex = 0;
if (fPaintOverrides.fFlags & flag) {
if (fPaintOverrides.*flag) {
itemIndex = (fPaint.*isFlag)() ? 2 : 1;
}
if (ImGui::Combo(label, &itemIndex, items)) {
if (itemIndex == 0) {
fPaintOverrides.fFlags &= ~flag;
fPaintOverrides.*flag = false;
} else {
fPaintOverrides.fFlags |= flag;
fPaintOverrides.*flag = true;
(fPaint.*setFlag)(itemIndex == 2);
}
paramsChanged = true;
@ -1714,39 +1714,90 @@ void Viewer::drawImGui() {
paintFlag("Dither",
"Default\0No Dither\0Dither\0\0",
SkPaint::kDither_Flag,
&SkPaintFields::fDither,
&SkPaint::isDither, &SkPaint::setDither);
#if 0
paintFlag("Fake Bold Glyphs",
}
if (ImGui::CollapsingHeader("Font")) {
int hintingIdx = 0;
if (fFontOverrides.fHinting) {
hintingIdx = SkTo<int>(fFont.getHinting()) + 1;
}
if (ImGui::Combo("Hinting", &hintingIdx,
"Default\0None\0Slight\0Normal\0Full\0\0"))
{
if (hintingIdx == 0) {
fFontOverrides.fHinting = false;
fFont.setHinting(kNo_SkFontHinting);
} else {
fFont.setHinting(SkTo<SkFontHinting>(hintingIdx - 1));
fFontOverrides.fHinting = true;
}
paramsChanged = true;
}
auto fontFlag = [this, &paramsChanged](const char* label, const char* items,
bool SkFontFields::* flag,
bool (SkFont::* isFlag)() const,
void (SkFont::* setFlag)(bool) )
{
int itemIndex = 0;
if (fFontOverrides.*flag) {
itemIndex = (fFont.*isFlag)() ? 2 : 1;
}
if (ImGui::Combo(label, &itemIndex, items)) {
if (itemIndex == 0) {
fFontOverrides.*flag = false;
} else {
fFontOverrides.*flag = true;
(fFont.*setFlag)(itemIndex == 2);
}
paramsChanged = true;
}
};
fontFlag("Fake Bold Glyphs",
"Default\0No Fake Bold\0Fake Bold\0\0",
SkPaint::kFakeBoldText_Flag,
&SkPaint::isFakeBoldText, &SkPaint::setFakeBoldText);
&SkFontFields::fEmbolden,
&SkFont::isEmbolden, &SkFont::setEmbolden);
paintFlag("Linear Text",
fontFlag("Linear Text",
"Default\0No Linear Text\0Linear Text\0\0",
SkPaint::kLinearText_Flag,
&SkPaint::isLinearText, &SkPaint::setLinearText);
&SkFontFields::fLinearMetrics,
&SkFont::isLinearMetrics, &SkFont::setLinearMetrics);
paintFlag("Subpixel Position Glyphs",
fontFlag("Subpixel Position Glyphs",
"Default\0Pixel Text\0Subpixel Text\0\0",
SkPaint::kSubpixelText_Flag,
&SkPaint::isSubpixelText, &SkPaint::setSubpixelText);
&SkFontFields::fSubpixel,
&SkFont::isSubpixel, &SkFont::setSubpixel);
paintFlag("Subpixel Anti-Alias",
"Default\0lcd\0LCD\0\0",
SkPaint::kLCDRenderText_Flag,
&SkPaint::isLCDRenderText, &SkPaint::setLCDRenderText);
paintFlag("Embedded Bitmap Text",
fontFlag("Embedded Bitmap Text",
"Default\0No Embedded Bitmaps\0Embedded Bitmaps\0\0",
SkPaint::kEmbeddedBitmapText_Flag,
&SkPaint::isEmbeddedBitmapText, &SkPaint::setEmbeddedBitmapText);
&SkFontFields::fEmbeddedBitmaps,
&SkFont::isEmbeddedBitmaps, &SkFont::setEmbeddedBitmaps);
paintFlag("Force Auto-Hinting",
fontFlag("Force Auto-Hinting",
"Default\0No Force Auto-Hinting\0Force Auto-Hinting\0\0",
SkPaint::kAutoHinting_Flag,
&SkPaint::isAutohinted, &SkPaint::setAutohinted);
#endif
&SkFontFields::fForceAutoHinting,
&SkFont::isForceAutoHinting, &SkFont::setForceAutoHinting);
int edgingIdx = 0;
if (fFontOverrides.fEdging) {
edgingIdx = SkTo<int>(fFont.getEdging()) + 1;
}
if (ImGui::Combo("Edging", &edgingIdx,
"Default\0Alias\0Antialias\0Subpixel Antialias\0\0"))
{
if (edgingIdx == 0) {
fFontOverrides.fEdging = false;
fFont.setEdging(SkFont::Edging::kAlias);
} else {
fFont.setEdging(SkTo<SkFont::Edging>(edgingIdx-1));
fFontOverrides.fEdging = true;
}
paramsChanged = true;
}
ImGui::Checkbox("Override TextSize", &fFontOverrides.fTextSize);
if (fFontOverrides.fTextSize) {
ImGui::DragFloat2("TextRange", fFontOverrides.fTextSizeRange,

View File

@ -47,6 +47,10 @@ public:
bool fHinting = false;
bool fEdging = false;
bool fSubpixel = false;
bool fForceAutoHinting = false;
bool fEmbeddedBitmaps = false;
bool fLinearMetrics = false;
bool fEmbolden = false;
};
struct SkPaintFields {
bool fPathEffect = false;
@ -61,7 +65,8 @@ public:
bool fMiterLimit = false;
bool fBlendMode = false;
uint32_t fFlags = 0;
bool fAntiAlias = false;
bool fDither = false;
enum class AntiAliasState {
Alias,
Normal,
@ -69,7 +74,7 @@ public:
AnalyticAAForced,
DeltaAAEnabled,
DeltaAAForced,
} fAntiAlias = AntiAliasState::Alias;
} fAntiAliasState = AntiAliasState::Alias;
const bool fOriginalSkUseAnalyticAA = gSkUseAnalyticAA;
const bool fOriginalSkForceAnalyticAA = gSkForceAnalyticAA;
const bool fOriginalSkUseDeltaAA = gSkUseDeltaAA;