/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Circle's radius is 40 but the total radius includes half the stroke width. #define CIRCLE_TOTAL_AREA (M_PI * 50 * 50) // The fill area's radius is the circle's radius minus half the stroke width. #define CIRCLE_FILL_AREA (M_PI * 30 * 30) #define CIRCLE_STROKE_AREA (CIRCLE_TOTAL_AREA - CIRCLE_FILL_AREA)
// Allow 2% margin of error to allow for blending #define ASSERT_NEARLY(val1, val2) \
{ \
ASSERT_GT(val1, (val2) * 0.98); \
ASSERT_LT(val1, (val2) * 1.02); \
}
class SvgPaintContext : public nsISVGPaintContext { public:
NS_DECL_ISUPPORTS
// Let the Image know we've sent all the data.
rv = image->OnImageDataComplete(channel, NS_OK, true);
ASSERT_NS_SUCCEEDED(rv);
// The final load event from the SVG document is dispatched asynchronously so // wait for that to happen.
MOZ_ALWAYS_TRUE(
SpinEventLoopUntil("windows:widget:TEST(TestWindowGfx, CreateIcon)"_ns,
[&listener]() { return listener->mIsLoaded; }));
image.forget(aImage);
}
void ConvertToRaster(imgIContainer* vectorImage, imgIContainer** aImage) { // First we encode it as a png image.
nsCOMPtr<imgITools> imgTools =
do_CreateInstance("@mozilla.org/image/tools;1");
// And then we load the image again as a raster imgIContainer
RefPtr<image::Image> image =
ImageFactory::CreateAnonymousImage("image/png"_ns, size);
RefPtr<ProgressTracker> tracker = image->GetProgressTracker();
ASSERT_FALSE(image->HasError());
// Let the Image know we've sent all the data.
rv = image->OnImageDataComplete(nullptr, NS_OK, true);
tracker->SyncNotifyProgress(FLAG_LOAD_COMPLETE);
ASSERT_NS_SUCCEEDED(rv);
int lines =
GetDIBits(::GetDC(nullptr), ii.hbmColor, 0, (UINT)bm.bmHeight,
(void*)bitmapData.get(), (BITMAPINFO*)&bi, DIB_RGB_COLORS); if (lines != bm.bmHeight) { return;
}
for (long y = 0; y < bm.bmHeight; y++) { auto index = stride * y;
for (long x = 0; x < bm.bmWidth; x++) { // Pixels are in BGRA format. double blue = bitmapData[index++] / 255.0; double green = bitmapData[index++] / 255.0; double red = bitmapData[index++] / 255.0; double alpha = bitmapData[index++] / 255.0;
*redCount += red * alpha;
*greenCount += green * alpha;
*blueCount += blue * alpha;
}
}
}
// Tests that we can scale down an image
TEST(TestWindowGfx, CreateIcon_ScaledDown)
{ auto Test = [](imgIContainer* image) {
HICON icon;
nsresult rv =
nsWindowGfx::CreateIcon(image, nullptr, false, LayoutDeviceIntPoint(),
LayoutDeviceIntSize(50, 50), &icon);
ASSERT_NS_SUCCEEDED(rv);
// Tests that we can scale up an image
TEST(TestWindowGfx, CreateIcon_ScaledUp)
{ auto Test = [](imgIContainer* image) {
HICON icon;
nsresult rv =
nsWindowGfx::CreateIcon(image, nullptr, false, LayoutDeviceIntPoint(),
LayoutDeviceIntSize(200, 200), &icon);
ASSERT_NS_SUCCEEDED(rv);
// Tests that we can render an image at its intrinsic size
TEST(TestWindowGfx, CreateIcon_Intrinsic)
{ auto Test = [](imgIContainer* image) {
HICON icon;
nsresult rv =
nsWindowGfx::CreateIcon(image, nullptr, false, LayoutDeviceIntPoint(),
LayoutDeviceIntSize(), &icon);
ASSERT_NS_SUCCEEDED(rv);
// If an SVG has no intrinsic size and we don't provide one we fail.
TEST(TestWindowGfx, CreateIcon_SVG_NoSize)
{
nsCOMPtr<imgIContainer> image;
LoadImage(SVG_UNSIZED_CIRCLE, getter_AddRefs(image));
// But we can still render an SVG with no intrinsic size as long as we provide // one.
TEST(TestWindowGfx, CreateIcon_SVG_NoIntrinsic)
{
nsCOMPtr<imgIContainer> image;
LoadImage(SVG_UNSIZED_CIRCLE, getter_AddRefs(image));
if (ii.hbmMask) DeleteObject(ii.hbmMask); if (ii.hbmColor) DeleteObject(ii.hbmColor);
::DestroyIcon(icon);
}
// Tests that we can set SVG context-fill and context-stroke
TEST(TestWindowGfx, CreateIcon_SVG_Context)
{ // Normally the context properties don't work for content documents including // data URIs.
Preferences::SetBool("svg.context-properties.content.enabled", true); // This test breaks if color management is enabled and an earlier gtest may // have enabled it.
gfxPlatform::SetCMSModeOverride(CMSMode::Off);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.