1
1
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
2
- index 97cf24ad5f4a6..ae9f65e7bfcaa 100644
2
+ index 97cf24ad5f4a6..859cb35da1f54 100644
3
3
--- a/content/renderer/render_frame_impl.cc
4
4
+++ b/content/renderer/render_frame_impl.cc
5
- @@ -256,6 +256,13 @@
5
+ @@ -256,6 +256,15 @@
6
6
#include "content/renderer/java/gin_java_bridge_dispatcher.h"
7
7
#endif
8
8
9
+ + // html2svg includes
10
+ + #include <iostream>
9
11
+ #include "cc/paint/paint_recorder.h"
10
12
+ #include "cc/paint/skia_paint_canvas.h"
11
13
+ #include "third_party/skia/include/core/SkStream.h"
@@ -16,11 +18,33 @@ index 97cf24ad5f4a6..ae9f65e7bfcaa 100644
16
18
using base::Time;
17
19
using blink::ContextMenuData;
18
20
using blink::WebContentDecryptionModule;
19
- @@ -3822,6 +3829,96 @@ void RenderFrameImpl::DidClearWindowObject() {
21
+ @@ -3822,6 +3831,108 @@ void RenderFrameImpl::DidClearWindowObject() {
20
22
21
23
for (auto& observer : observers_)
22
24
observer.DidClearWindowObject();
23
25
+
26
+ + // A Skia stream writing to stdout
27
+ + class StdoutStream : public SkWStream {
28
+ + public:
29
+ + bool write(const void* data, size_t size) override {
30
+ + std::cout.write(static_cast<const char*>(data), size);
31
+ + fBytesWritten += size;
32
+ +
33
+ + return true;
34
+ + }
35
+ +
36
+ + void flush() override {
37
+ + std::cout.flush();
38
+ + }
39
+ +
40
+ + size_t bytesWritten() const override {
41
+ + return fBytesWritten;
42
+ + }
43
+ +
44
+ + private:
45
+ + size_t fBytesWritten = 0;
46
+ + };
47
+ +
24
48
+ // Get access to the JS VM for this process (each tab is a process)
25
49
+ v8::Isolate *isolate = blink::MainThreadIsolate();
26
50
+ // Auto-clean v8 handles
@@ -49,58 +73,48 @@ index 97cf24ad5f4a6..ae9f65e7bfcaa 100644
49
73
+ // Get the page size
50
74
+ auto size = frame->DocumentSize();
51
75
+ // Create a memory stream to save the SVG content
52
- + SkDynamicMemoryWStream stream;
53
- +
54
- + {
55
- + // Create an SVG canvas with the dimensions of the layer
56
- + int width = size.width(), height = size.height();
76
+ + StdoutStream stream;
77
+ + // Create an SVG canvas with the dimensions of the layer
78
+ + int width = size.width(), height = size.height();
57
79
+
58
- + cc::PaintRecorder recorder;
59
- + auto rect = SkRect::MakeWH(width, height);
80
+ + cc::PaintRecorder recorder;
81
+ + auto rect = SkRect::MakeWH(width, height);
60
82
+
61
- + frame->CapturePaintPreview(
62
- + gfx::Rect(0, 0, width, height),
63
- + recorder.beginRecording(rect),
64
- + false,
65
- + true
66
- + );
83
+ + frame->CapturePaintPreview(
84
+ + gfx::Rect(0, 0, width, height),
85
+ + recorder.beginRecording(rect),
86
+ + false,
87
+ + true
88
+ + );
67
89
+
68
- + auto picture = recorder.finishRecordingAsPicture();
90
+ + auto picture = recorder.finishRecordingAsPicture();
69
91
+
70
- + switch(args[0]->ToUint32(context).ToLocalChecked()->Value()) {
71
- + // SVG
72
- + case 0: {
73
- + picture->Playback(SkSVGCanvas::Make(rect, &stream).get());
92
+ + switch(args[0]->ToUint32(context).ToLocalChecked()->Value()) {
93
+ + // SVG
94
+ + case 0: {
95
+ + picture->Playback(SkSVGCanvas::Make(rect, &stream).get());
74
96
+
75
- + break;
76
- + }
77
- + // PDF
78
- + case 1: {
79
- + SkPDF::Metadata metadata;
80
- + v8::String::Utf8Value title(isolate, args[1]);
97
+ + break;
98
+ + }
99
+ + // PDF
100
+ + case 1: {
101
+ + SkPDF::Metadata metadata;
102
+ + v8::String::Utf8Value title(isolate, args[1]);
81
103
+
82
- + metadata.fTitle = *title;
83
- + metadata.fCreator = "html2svg PDF back-end";
104
+ + metadata.fTitle = *title;
105
+ + metadata.fCreator = "html2svg PDF back-end";
84
106
+
85
- + auto document = SkPDF::MakeDocument(&stream, metadata);
107
+ + auto document = SkPDF::MakeDocument(&stream, metadata);
86
108
+
87
- + picture->Playback(document->beginPage(rect.width(), rect.height()));
88
- + document->endPage();
89
- + document->close();
109
+ + picture->Playback(document->beginPage(rect.width(), rect.height()));
110
+ + document->endPage();
111
+ + document->close();
90
112
+
91
- + break;
92
- + }
113
+ + break;
93
114
+ }
94
115
+ }
95
116
+
96
- + // Allocate a buffer to hold the SVG data
97
- + auto buffer = v8::ArrayBuffer::New(isolate, stream.bytesWritten());
98
- +
99
- + // Copy from the stream to the buffer
100
- + stream.copyTo(buffer->GetBackingStore()->Data());
101
- +
102
- + // Return the data to the JS world
103
- + args.GetReturnValue().Set(buffer);
117
+ + stream.flush();
104
118
+ }
105
119
+ );
106
120
+
0 commit comments