c0bd9f9fe5
Current strategy: everything from the top Things to look at first are the manual changes: - added tools/rewrite_includes.py - removed -Idirectives from BUILD.gn - various compile.sh simplifications - tweak tools/embed_resources.py - update gn/find_headers.py to write paths from the top - update gn/gn_to_bp.py SkUserConfig.h layout so that #include "include/config/SkUserConfig.h" always gets the header we want. No-Presubmit: true Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706 Commit-Queue: Mike Klein <mtklein@google.com> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Brian Osman <brianosman@google.com> Reviewed-by: Florin Malita <fmalita@chromium.org>
104 lines
3.5 KiB
C++
104 lines
3.5 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkFont.h"
|
|
#include "include/core/SkFontMgr.h"
|
|
#include "include/core/SkTypeface.h"
|
|
#include "include/ports/SkFontMgr_fontconfig.h"
|
|
#include "tests/Test.h"
|
|
#include "tools/Resources.h"
|
|
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
static bool bitmap_compare(const SkBitmap& ref, const SkBitmap& test) {
|
|
for (int y = 0; y < test.height(); ++y) {
|
|
for (int x = 0; x < test.width(); ++x) {
|
|
SkColor testColor = test.getColor(x, y);
|
|
SkColor refColor = ref.getColor(x, y);
|
|
if (refColor != testColor) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
DEF_TEST(FontMgrFontConfig, reporter) {
|
|
FcConfig* config = FcConfigCreate();
|
|
|
|
// FontConfig may modify the passed path (make absolute or other).
|
|
FcConfigSetSysRoot(config, reinterpret_cast<const FcChar8*>(GetResourcePath("").c_str()));
|
|
// FontConfig will lexically compare paths against its version of the sysroot.
|
|
SkString distortablePath(reinterpret_cast<const char*>(FcConfigGetSysRoot(config)));
|
|
distortablePath += "/fonts/Distortable.ttf";
|
|
FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(distortablePath.c_str()));
|
|
|
|
FcConfigBuildFonts(config);
|
|
|
|
sk_sp<SkFontMgr> fontMgr(SkFontMgr_New_FontConfig(config));
|
|
sk_sp<SkTypeface> typeface(fontMgr->legacyMakeTypeface("Distortable", SkFontStyle()));
|
|
if (!typeface) {
|
|
ERRORF(reporter, "Could not find typeface. FcVersion: %d", FcGetVersion());
|
|
return;
|
|
}
|
|
|
|
SkBitmap bitmapStream;
|
|
bitmapStream.allocN32Pixels(64, 64);
|
|
SkCanvas canvasStream(bitmapStream);
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
|
|
SkBitmap bitmapClone;
|
|
bitmapClone.allocN32Pixels(64, 64);
|
|
SkCanvas canvasClone(bitmapClone);
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
|
|
SkPaint paint;
|
|
paint.setColor(SK_ColorGRAY);
|
|
|
|
constexpr float kTextSize = 20;
|
|
|
|
std::unique_ptr<SkStreamAsset> distortableStream(
|
|
GetResourceAsStream("fonts/Distortable.ttf"));
|
|
if (!distortableStream) {
|
|
return;
|
|
}
|
|
|
|
SkPoint point = SkPoint::Make(20.0f, 20.0f);
|
|
SkFourByteTag tag = SkSetFourByteTag('w', 'g', 'h', 't');
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
SkScalar styleValue =
|
|
SkDoubleToScalar(0.5 + i * ((2.0 - 0.5) / 10));
|
|
SkFontArguments::VariationPosition::Coordinate
|
|
coordinates[] = {{tag, styleValue}};
|
|
SkFontArguments::VariationPosition
|
|
position = {coordinates, SK_ARRAY_COUNT(coordinates)};
|
|
|
|
SkFont fontStream(
|
|
fontMgr->makeFromStream(distortableStream->duplicate(),
|
|
SkFontArguments().setVariationDesignPosition(position)),
|
|
kTextSize);
|
|
fontStream.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
SkFont fontClone(
|
|
typeface->makeClone(SkFontArguments().setVariationDesignPosition(position)), kTextSize);
|
|
fontClone.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
|
|
|
constexpr char text[] = "abc";
|
|
|
|
canvasStream.drawColor(SK_ColorWHITE);
|
|
canvasStream.drawString(text, point.fX, point.fY, fontStream, paint);
|
|
|
|
canvasClone.drawColor(SK_ColorWHITE);
|
|
canvasClone.drawString(text, point.fX, point.fY, fontClone, paint);
|
|
|
|
bool success = bitmap_compare(bitmapStream, bitmapClone);
|
|
REPORTER_ASSERT(reporter, success);
|
|
}
|
|
}
|