[PDF Ink Signatures] Add real data to PDFiumInkWriterTest.Basic
Take the real ink::StrokeInput data from a sample stroke and plug it into PDFiumInkWriterTest. Use it to generate a real ink::ModeledShape. Bug: 335517469 Change-Id: I65ad8f03c3d113945c71949629d84410b4227da4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5889705 Reviewed-by: Alan Screen <awscreen@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1360672}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
2b5221a085
commit
201398ce7f
@ -4,13 +4,17 @@
|
||||
|
||||
#include "pdf/pdfium/pdfium_ink_writer.h"
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/span.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/time/time.h"
|
||||
#include "pdf/pdf_ink_brush.h"
|
||||
#include "pdf/pdf_ink_conversions.h"
|
||||
#include "pdf/pdfium/pdfium_engine.h"
|
||||
#include "pdf/pdfium/pdfium_engine_exports.h"
|
||||
#include "pdf/pdfium/pdfium_page.h"
|
||||
@ -18,11 +22,14 @@
|
||||
#include "pdf/test/test_client.h"
|
||||
#include "pdf/test/test_helpers.h"
|
||||
#include "printing/units.h"
|
||||
#include "third_party/ink/src/ink/strokes/input/stroke_input.h"
|
||||
#include "third_party/ink/src/ink/strokes/input/stroke_input_batch.h"
|
||||
#include "third_party/ink/src/ink/strokes/stroke.h"
|
||||
#include "third_party/pdfium/public/fpdfview.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkImage.h"
|
||||
#include "third_party/skia/include/core/SkImageInfo.h"
|
||||
#include "ui/gfx/geometry/point_f.h"
|
||||
#include "ui/gfx/geometry/size.h"
|
||||
#include "ui/gfx/geometry/skia_conversions.h"
|
||||
|
||||
@ -32,6 +39,61 @@ namespace {
|
||||
|
||||
constexpr PdfInkBrush::Params kBasicBrushParams = {SK_ColorRED, 4.0f};
|
||||
|
||||
struct InputData {
|
||||
gfx::PointF position;
|
||||
base::TimeDelta time;
|
||||
};
|
||||
|
||||
constexpr auto kBasicInputs = std::to_array<InputData>({
|
||||
{{126.122f, 52.852f}, base::Seconds(0.0f)},
|
||||
{{127.102f, 52.2398f}, base::Seconds(0.031467f)},
|
||||
{{130.041f, 50.7704f}, base::Seconds(0.07934f)},
|
||||
{{132.49f, 50.2806f}, base::Seconds(0.11225f)},
|
||||
{{133.714f, 49.7908f}, base::Seconds(0.143326f)},
|
||||
{{134.204f, 49.7908f}, base::Seconds(0.187606f)},
|
||||
{{135.184f, 49.7908f}, base::Seconds(0.20368f)},
|
||||
{{136.408f, 50.5255f}, base::Seconds(0.232364f)},
|
||||
{{137.143f, 52.2398f}, base::Seconds(0.261512f)},
|
||||
{{137.878f, 54.4439f}, base::Seconds(0.290249f)},
|
||||
{{137.878f, 55.9133f}, base::Seconds(0.316557f)},
|
||||
{{137.878f, 57.3827f}, base::Seconds(0.341756f)},
|
||||
{{137.143f, 58.852f}, base::Seconds(0.37093f)},
|
||||
{{136.408f, 59.8316f}, base::Seconds(0.39636f)},
|
||||
{{135.184f, 60.3214f}, base::Seconds(0.421022f)},
|
||||
{{134.694f, 60.3214f}, base::Seconds(0.450936f)},
|
||||
{{133.714f, 60.8112f}, base::Seconds(0.475798f)},
|
||||
{{132.245f, 60.8112f}, base::Seconds(0.501089f)},
|
||||
{{130.531f, 61.0561f}, base::Seconds(0.525835f)},
|
||||
{{130.041f, 61.301f}, base::Seconds(0.551003f)},
|
||||
{{129.306f, 61.301f}, base::Seconds(0.575968f)},
|
||||
{{128.816f, 61.301f}, base::Seconds(0.618475f)},
|
||||
{{128.327f, 61.0561f}, base::Seconds(0.634891f)},
|
||||
{{127.347f, 60.0765f}, base::Seconds(0.668079f)},
|
||||
{{126.612f, 59.0969f}, base::Seconds(0.692914f)},
|
||||
{{126.122f, 58.3622f}, base::Seconds(0.718358f)},
|
||||
{{125.878f, 57.1378f}, base::Seconds(0.743602f)},
|
||||
{{125.388f, 55.9133f}, base::Seconds(0.768555f)},
|
||||
{{125.143f, 54.6888f}, base::Seconds(0.794048f)},
|
||||
{{125.143f, 54.199f}, base::Seconds(0.819457f)},
|
||||
{{125.143f, 53.7092f}, base::Seconds(0.851297f)},
|
||||
{{125.388f, 53.4643f}, base::Seconds(0.901739f)},
|
||||
{{125.633f, 53.2194f}, base::Seconds(0.951174f)},
|
||||
{{125.878f, 53.2194f}, base::Seconds(0.985401f)},
|
||||
});
|
||||
|
||||
std::optional<ink::StrokeInputBatch> CreateInputBatch(
|
||||
base::span<const InputData> inputs) {
|
||||
ink::StrokeInputBatch input_batch;
|
||||
for (const auto& input : inputs) {
|
||||
auto result = input_batch.Append(CreateInkStrokeInput(
|
||||
ink::StrokeInput::ToolType::kMouse, input.position, input.time));
|
||||
if (!result.ok()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
return input_batch;
|
||||
}
|
||||
|
||||
base::FilePath GetReferenceFilePath(std::string_view test_filename) {
|
||||
return base::FilePath(FILE_PATH_LITERAL("pdfium_ink"))
|
||||
.AppendASCII(test_filename);
|
||||
@ -83,8 +145,9 @@ TEST_P(PDFiumInkWriterTest, Basic) {
|
||||
auto brush =
|
||||
std::make_unique<PdfInkBrush>(PdfInkBrush::Type::kPen, kBasicBrushParams);
|
||||
|
||||
ink::Stroke stroke(brush->GetInkBrush());
|
||||
// TODO(crbug.com/335517469): Add some data to `stroke`.
|
||||
std::optional<ink::StrokeInputBatch> inputs = CreateInputBatch(kBasicInputs);
|
||||
ASSERT_TRUE(inputs.has_value());
|
||||
ink::Stroke stroke(brush->GetInkBrush(), inputs.value());
|
||||
ASSERT_TRUE(WriteStrokeToPage(page, stroke));
|
||||
|
||||
std::vector<uint8_t> saved_pdf_data = engine->GetSaveData();
|
||||
|
Reference in New Issue
Block a user