From 12a257d7f8da26b16637f34a73f8135e6da4d983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 9 Dec 2007 15:36:28 +0000 Subject: [PATCH] * make sure that the ApproximationScale() implementation of any Transformer not negative * PathSource can now remember a global scale, and the IconRenderer sets it, since this value is used in the curve converter for on the fly generation of vertices, this change does not affect anything and doesn't create the need to "update" the conversion pipeline to render an icon at different sizes (like Icon-O-Matic does) -> this change fixes edgy curves on icons rendered bigger than 64x64 as reported by Axel some time ago git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23093 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/icon/IconRenderer.cpp | 7 +++--- src/libs/icon/shape/Shape.cpp | 7 ++++++ src/libs/icon/shape/Shape.h | 1 + .../icon/transformer/AffineTransformer.cpp | 2 +- .../icon/transformer/ContourTransformer.cpp | 6 ++++- src/libs/icon/transformer/PathSource.cpp | 22 ++++++++++++++----- src/libs/icon/transformer/PathSource.h | 7 +++++- .../icon/transformer/StrokeTransformer.cpp | 6 ++++- 8 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/libs/icon/IconRenderer.cpp b/src/libs/icon/IconRenderer.cpp index 88fb317159..819297e8ab 100644 --- a/src/libs/icon/IconRenderer.cpp +++ b/src/libs/icon/IconRenderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006, Haiku. + * Copyright 2006-2007, Haiku. All rights reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -100,7 +100,7 @@ StyleHandler::color(unsigned styleIndex) { StyleItem* styleItem = (StyleItem*)fStyles.ItemAt(styleIndex); if (!styleItem) { - printf("no style at index: %d!\n", styleIndex); + printf("no style at index: %u!\n", styleIndex); return fTransparent; } @@ -120,7 +120,7 @@ StyleHandler::generate_span(agg::rgba8* span, int x, int y, { StyleItem* styleItem = (StyleItem*)fStyles.ItemAt(styleIndex); if (!styleItem || !styleItem->style->Gradient()) { - printf("no style/gradient at index: %d!\n", styleIndex); + printf("no style/gradient at index: %u!\n", styleIndex); // TODO: memset() span? return; } @@ -397,6 +397,7 @@ IconRenderer::_Render(const BRect& r) styleIndex++; // global scale + shape->SetGlobalScale(max_c(1.0, transform.scale())); ScaledPath scaledPath(shape->VertexSource(), transform); if (shape->Hinting()) { // additional hinting diff --git a/src/libs/icon/shape/Shape.cpp b/src/libs/icon/shape/Shape.cpp index 3960de6ca3..90e2a5ca83 100644 --- a/src/libs/icon/shape/Shape.cpp +++ b/src/libs/icon/shape/Shape.cpp @@ -482,6 +482,13 @@ Shape::VertexSource() return *source; } +// SetGlobalScale +void +Shape::SetGlobalScale(double scale) +{ + fPathSource.SetGlobalScale(scale); +} + // AddTransformer bool Shape::AddTransformer(Transformer* transformer) diff --git a/src/libs/icon/shape/Shape.h b/src/libs/icon/shape/Shape.h index 66e11c4377..e0d6ec4dac 100644 --- a/src/libs/icon/shape/Shape.h +++ b/src/libs/icon/shape/Shape.h @@ -105,6 +105,7 @@ class Shape : public BPrivate::Icon::Transformable { BRect Bounds(bool updateLast = false) const; ::VertexSource& VertexSource(); + void SetGlobalScale(double scale); bool AddTransformer(Transformer* transformer); bool AddTransformer(Transformer* transformer, diff --git a/src/libs/icon/transformer/AffineTransformer.cpp b/src/libs/icon/transformer/AffineTransformer.cpp index 9338d69e39..6277239c25 100644 --- a/src/libs/icon/transformer/AffineTransformer.cpp +++ b/src/libs/icon/transformer/AffineTransformer.cpp @@ -93,7 +93,7 @@ AffineTransformer::SetSource(VertexSource& source) double AffineTransformer::ApproximationScale() const { - return fSource.ApproximationScale() * scale(); + return fabs(fSource.ApproximationScale() * scale()); } // #pragma mark - diff --git a/src/libs/icon/transformer/ContourTransformer.cpp b/src/libs/icon/transformer/ContourTransformer.cpp index e5798c77b4..b88870cc3d 100644 --- a/src/libs/icon/transformer/ContourTransformer.cpp +++ b/src/libs/icon/transformer/ContourTransformer.cpp @@ -111,7 +111,11 @@ ContourTransformer::SetSource(VertexSource& source) double ContourTransformer::ApproximationScale() const { - return fSource.ApproximationScale() * width(); + double scale = fSource.ApproximationScale(); + double factor = fabs(width()); + if (factor > 1.0) + scale *= factor; + return scale; } // #pragma mark - diff --git a/src/libs/icon/transformer/PathSource.cpp b/src/libs/icon/transformer/PathSource.cpp index 7422995eb8..174bfb56ec 100644 --- a/src/libs/icon/transformer/PathSource.cpp +++ b/src/libs/icon/transformer/PathSource.cpp @@ -13,10 +13,13 @@ // constructor PathSource::PathSource(PathContainer* paths) - : VertexSource(), - fPaths(paths), - fAGGPath(), - fAGGCurvedPath(fAGGPath) + : VertexSource() + , fPaths(paths) + , fAGGPath() + , fAGGCurvedPath(fAGGPath) + + , fGlobalScale(1.0) + , fLastTransformerScale(1.0) { } @@ -68,6 +71,15 @@ PathSource::Update(bool leavePathsOpen, double approximationScale) fAGGPath.close_polygon(); } - fAGGCurvedPath.approximation_scale(approximationScale); + fLastTransformerScale = approximationScale; + fAGGCurvedPath.approximation_scale(fLastTransformerScale * fGlobalScale); +} + +// SetGlobalScale +void +PathSource::SetGlobalScale(double scale) +{ + fGlobalScale = scale; + fAGGCurvedPath.approximation_scale(fLastTransformerScale * fGlobalScale); } diff --git a/src/libs/icon/transformer/PathSource.h b/src/libs/icon/transformer/PathSource.h index 10046738e8..3de12de895 100644 --- a/src/libs/icon/transformer/PathSource.h +++ b/src/libs/icon/transformer/PathSource.h @@ -37,12 +37,17 @@ class PathSource : public VertexSource { // PathSource void Update(bool leavePathsOpen, - double approximationScale); + double approximationScale); + + void SetGlobalScale(double scale); private: PathContainer* fPaths; AGGPath fAGGPath; AGGCurvedPath fAGGCurvedPath; + + double fGlobalScale; + double fLastTransformerScale; }; } // namespace Icon diff --git a/src/libs/icon/transformer/StrokeTransformer.cpp b/src/libs/icon/transformer/StrokeTransformer.cpp index 4997a0e394..7ef5726efc 100644 --- a/src/libs/icon/transformer/StrokeTransformer.cpp +++ b/src/libs/icon/transformer/StrokeTransformer.cpp @@ -121,7 +121,11 @@ StrokeTransformer::WantsOpenPaths() const double StrokeTransformer::ApproximationScale() const { - return fSource.ApproximationScale() * width(); + double scale = fSource.ApproximationScale(); + double factor = fabs(width()); + if (factor > 1.0) + scale *= factor; + return scale; } // #pragma mark -