[PDF Ink Signatures] Make ink::Brush in PdfInkBrush mutable
Make ink::Brush in PdfInkBrush mutable and provide SetColor() and SetSize() methods to change the brush parameters. This will be used in future CL https://crrev.com/c/5932590, so that a new PdfInkBrush does not have to be created every time the brush changes. Bug: 373672165 Change-Id: Ib8be7c5c0da454fa8c1715153007965a8bc94ca7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5932589 Reviewed-by: Lei Zhang <thestig@chromium.org> Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com> Commit-Queue: Andy Phan <andyphan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1370361}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
76aefd7272
commit
94ca9e06f1
@ -43,6 +43,17 @@ float GetOpacity(PdfInkBrush::Type type) {
|
||||
NOTREACHED();
|
||||
}
|
||||
|
||||
// ink::Brush actually uses ink::Color, but pdf/ uses SkColor. To avoid having
|
||||
// multiple color representations, do not expose ink::Color and just convert
|
||||
// `color`.
|
||||
ink::Color GetInkColorFromSkColor(SkColor color) {
|
||||
return ink::Color::FromUint8(
|
||||
/*red=*/SkColorGetR(color),
|
||||
/*green=*/SkColorGetG(color),
|
||||
/*blue=*/SkColorGetB(color),
|
||||
/*alpha=*/SkColorGetA(color));
|
||||
}
|
||||
|
||||
ink::Brush CreateInkBrush(PdfInkBrush::Type type, SkColor color, float size) {
|
||||
CHECK(PdfInkBrush::IsToolSizeInRange(size));
|
||||
|
||||
@ -56,16 +67,9 @@ ink::Brush CreateInkBrush(PdfInkBrush::Type type, SkColor color, float size) {
|
||||
/*uri_string=*/"");
|
||||
CHECK(family.ok());
|
||||
|
||||
// ink::Brush actually uses ink::Color, but pdf/ uses SkColor. To avoid having
|
||||
// multiple color representations, do not expose ink::Color and just convert
|
||||
// `color`.
|
||||
auto brush = ink::Brush::Create(*family,
|
||||
/*color=*/
|
||||
ink::Color::FromUint8(
|
||||
/*red=*/SkColorGetR(color),
|
||||
/*green=*/SkColorGetG(color),
|
||||
/*blue=*/SkColorGetB(color),
|
||||
/*alpha=*/SkColorGetA(color)),
|
||||
GetInkColorFromSkColor(color),
|
||||
/*size=*/size,
|
||||
/*epsilon=*/0.1f);
|
||||
CHECK(brush.ok());
|
||||
@ -118,4 +122,13 @@ gfx::Rect PdfInkBrush::GetInvalidateArea(const gfx::PointF& center1,
|
||||
return area2;
|
||||
}
|
||||
|
||||
void PdfInkBrush::SetColor(SkColor color) {
|
||||
ink_brush_.SetColor(GetInkColorFromSkColor(color));
|
||||
}
|
||||
|
||||
void PdfInkBrush::SetSize(float size) {
|
||||
auto size_result = ink_brush_.SetSize(std::move(size));
|
||||
CHECK(size_result.ok());
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -49,9 +49,12 @@ class PdfInkBrush {
|
||||
|
||||
const ink::Brush& ink_brush() const { return ink_brush_; }
|
||||
|
||||
void SetColor(SkColor color);
|
||||
|
||||
void SetSize(float size);
|
||||
|
||||
private:
|
||||
// The Ink brush initialized based on the PdfInkBrush ctor parameters.
|
||||
const ink::Brush ink_brush_;
|
||||
ink::Brush ink_brush_;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "pdf/pdf_ink_conversions.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
@ -45,4 +46,20 @@ TEST(PdfInkBrushTest, InvalidateDifferentPoints) {
|
||||
gfx::PointF(15.0f, 32.0f)));
|
||||
}
|
||||
|
||||
TEST(PdfInkBrushTest, SetColor) {
|
||||
auto brush = CreatePdfInkBrush(/*size=*/10.0f);
|
||||
EXPECT_EQ(SK_ColorBLACK, GetSkColorFromInkBrush(brush->ink_brush()));
|
||||
|
||||
brush->SetColor(SK_ColorCYAN);
|
||||
EXPECT_EQ(SK_ColorCYAN, GetSkColorFromInkBrush(brush->ink_brush()));
|
||||
}
|
||||
|
||||
TEST(PdfInkBrushTest, SetSize) {
|
||||
auto brush = CreatePdfInkBrush(/*size=*/10.0f);
|
||||
EXPECT_EQ(10.0f, brush->ink_brush().GetSize());
|
||||
|
||||
brush->SetSize(4.0f);
|
||||
EXPECT_EQ(4.0f, brush->ink_brush().GetSize());
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
Reference in New Issue
Block a user