[PDF Ink Signatures] Introduce PdfInkBrush
Introduce chrome_pdf::PdfInkBrush, which is a wrapper class for chrome_pdf::InkBrush. The purpose of PdfInkBrush is to provide an easy way to quickly create certain brushes used only for PDF annotation mode. For example, PDF annotation mode currently only needs a pen, highlighter, and eraser. The pen and highlighter should have a certain tip, transparency, etc. PdfInkBrush uses the brush type and relevant parameters to quickly create preset InkBrushes. PdfInkBrush::CreateInkBrush() will be implemented and used in https://crrev.com/c/5550545. Low-Coverage-Reason: TESTS_IN_SEPARATE_CL. Class is unused in current CL, and is used in https://crrev.com/c/5550545. Bug: 335524382 Change-Id: I200c994d0d903fe745ec9ecd9f8ad3cd15d98474 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5550544 Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: Andy Phan <andyphan@chromium.org> Cr-Commit-Position: refs/heads/main@{#1304484}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4660d2d8a7
commit
28a749024b
@ -196,6 +196,8 @@ if (enable_pdf) {
|
||||
sources += [
|
||||
"ink_module.cc",
|
||||
"ink_module.h",
|
||||
"pdf_ink_brush.cc",
|
||||
"pdf_ink_brush.h",
|
||||
]
|
||||
|
||||
public_deps += [ "//pdf/ink" ]
|
||||
|
37
pdf/pdf_ink_brush.cc
Normal file
37
pdf/pdf_ink_brush.cc
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "pdf/pdf_ink_brush.h"
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include "base/check_op.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
// static
|
||||
std::optional<PdfInkBrush::Type> PdfInkBrush::StringToType(
|
||||
const std::string& brush_type) {
|
||||
if (brush_type == "highlighter") {
|
||||
return Type::kHighlighter;
|
||||
}
|
||||
if (brush_type == "pen") {
|
||||
return Type::kPen;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
PdfInkBrush::PdfInkBrush(Type brush_type, Params brush_params)
|
||||
: type_(brush_type), params_(brush_params) {
|
||||
CHECK_GT(brush_params.size, 0);
|
||||
}
|
||||
|
||||
PdfInkBrush::~PdfInkBrush() = default;
|
||||
|
||||
std::unique_ptr<InkBrush> PdfInkBrush::CreateInkBrush() {
|
||||
// TODO(crbug.com/335524382): Implement this.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace chrome_pdf
|
61
pdf/pdf_ink_brush.h
Normal file
61
pdf/pdf_ink_brush.h
Normal file
@ -0,0 +1,61 @@
|
||||
// Copyright 2024 The Chromium Authors
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef PDF_PDF_INK_BRUSH_H_
|
||||
#define PDF_PDF_INK_BRUSH_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
class InkBrush;
|
||||
|
||||
// A wrapper class used to create ink brushes specifically for PDF annotation
|
||||
// mode.
|
||||
// TODO(crbug.com/335524382): Add unit tests that check that `PdfInkBrush`
|
||||
// properly creates `InkBrush` instances.
|
||||
class PdfInkBrush {
|
||||
public:
|
||||
// The types of brushes supported in PDF annotation mode.
|
||||
enum class Type {
|
||||
kHighlighter,
|
||||
kPen,
|
||||
};
|
||||
|
||||
// Converts `brush_type` to a `Type`, returning `std::nullopt` if `brush_type`
|
||||
// does not correspond to any `Type`.
|
||||
static std::optional<Type> StringToType(const std::string& brush_type);
|
||||
|
||||
// Parameters for the brush.
|
||||
struct Params {
|
||||
SkColor color;
|
||||
float size;
|
||||
};
|
||||
|
||||
PdfInkBrush(Type brush_type, Params brush_params);
|
||||
|
||||
PdfInkBrush(const PdfInkBrush&) = delete;
|
||||
PdfInkBrush& operator=(const PdfInkBrush&) = delete;
|
||||
~PdfInkBrush();
|
||||
|
||||
Type type() const { return type_; }
|
||||
|
||||
const Params& params() const { return params_; }
|
||||
|
||||
// Returns a new ink brush of `type_` with `params_` Returns nullptr if failed
|
||||
// to create an ink brush.
|
||||
std::unique_ptr<InkBrush> CreateInkBrush();
|
||||
|
||||
private:
|
||||
Type type_;
|
||||
Params params_;
|
||||
};
|
||||
|
||||
} // namespace chrome_pdf
|
||||
|
||||
#endif // PDF_PDF_INK_BRUSH_H_
|
Reference in New Issue
Block a user