Skip to content

Commit 882332d

Browse files
authored
feat: complete unicode support (#20)
1 parent 48df491 commit 882332d

File tree

4 files changed

+230
-94
lines changed

4 files changed

+230
-94
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ FROM node:18
100100
RUN apt-get update && \
101101
apt-get install --yes \
102102
libglib2.0-0 libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libgtk-3-0 libgbm1 libasound2 \
103-
xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps
103+
xvfb x11-xkb-utils xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic x11-apps \
104+
fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho fonts-ipafont-gothic fonts-unfonts-core fonts-noto-core
104105

105106
WORKDIR /app
106107
COPY package.json yarn.lock /app/

src/chromium.patch

+102-55
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc
2-
index 97cf24ad5f4a6..022d02c8cacf9 100644
2+
index 97cf24ad5f4a6..ab3f90752b11a 100644
33
--- a/content/renderer/render_frame_impl.cc
44
+++ b/content/renderer/render_frame_impl.cc
55
@@ -256,6 +256,15 @@
@@ -18,7 +18,7 @@ index 97cf24ad5f4a6..022d02c8cacf9 100644
1818
using base::Time;
1919
using blink::ContextMenuData;
2020
using blink::WebContentDecryptionModule;
21-
@@ -3822,6 +3831,134 @@ void RenderFrameImpl::DidClearWindowObject() {
21+
@@ -3822,6 +3831,135 @@ void RenderFrameImpl::DidClearWindowObject() {
2222

2323
for (auto& observer : observers_)
2424
observer.DidClearWindowObject();
@@ -43,6 +43,7 @@ index 97cf24ad5f4a6..022d02c8cacf9 100644
4343
+ std::memcpy(&fBytes[fBytesBuffered], &buffer[size - remaining], length);
4444
+
4545
+ remaining -= length;
46+
+ fBytesWritten += length;
4647
+ fBytesBuffered += length;
4748
+
4849
+ if (fBytesBuffered == bufferSize) {
@@ -226,71 +227,117 @@ index cb2b900c4ff50..765153f982c29 100644
226227

227228
UkmParameters HTMLCanvasElement::GetUkmParameters() {
228229
diff --git a/third_party/blink/renderer/platform/fonts/font.cc b/third_party/blink/renderer/platform/fonts/font.cc
229-
index 67ba540bfc2b0..f22e6988cf488 100644
230+
index 67ba540bfc2b0..19e909d455835 100644
230231
--- a/third_party/blink/renderer/platform/fonts/font.cc
231232
+++ b/third_party/blink/renderer/platform/fonts/font.cc
232-
@@ -230,15 +230,22 @@ void Font::DrawText(cc::PaintCanvas* canvas,
233+
@@ -47,6 +47,8 @@
234+
#include "third_party/skia/include/core/SkTextBlob.h"
235+
#include "ui/gfx/geometry/rect_f.h"
236+
237+
+#include "third_party/skia/include/utils/SkBase64.h"
238+
+
239+
namespace blink {
240+
241+
namespace {
242+
@@ -153,7 +155,11 @@ void DrawBlobs(cc::PaintCanvas* canvas,
243+
const cc::PaintFlags& flags,
244+
const ShapeResultBloberizer::BlobBuffer& blobs,
245+
const gfx::PointF& point,
246+
- cc::NodeId node_id = cc::kInvalidNodeId) {
247+
+ cc::NodeId node_id = cc::kInvalidNodeId) {
248+
+ if (getenv("html2svg_svg_mode") != nullptr) {
249+
+ return;
250+
+ }
251+
+
252+
for (const auto& blob_info : blobs) {
253+
DCHECK(blob_info.blob);
254+
cc::PaintCanvasAutoRestore auto_restore(canvas, false);
255+
@@ -198,8 +204,7 @@ void DrawBlobs(cc::PaintCanvas* canvas,
256+
}
257+
}
258+
if (node_id != cc::kInvalidNodeId) {
259+
- canvas->drawTextBlob(blob_info.blob, point.x(), point.y(), node_id,
260+
- flags);
261+
+ canvas->drawTextBlob(blob_info.blob, point.x(), point.y(), node_id, flags);
262+
} else {
263+
canvas->drawTextBlob(blob_info.blob, point.x(), point.y(), flags);
264+
}
265+
@@ -230,6 +235,37 @@ void Font::DrawText(cc::PaintCanvas* canvas,
233266
if (ShouldSkipDrawing())
234267
return;
235268

236-
- CachingWordShaper word_shaper(*this);
237-
- ShapeResultBuffer buffer;
238-
- word_shaper.FillResultBuffer(run_info, &buffer);
239-
- ShapeResultBloberizer::FillGlyphs bloberizer(
240-
- GetFontDescription(), device_scale_factor > 1.0f, run_info, buffer,
241-
- draw_type == Font::DrawType::kGlyphsOnly
242-
- ? ShapeResultBloberizer::Type::kNormal
243-
- : ShapeResultBloberizer::Type::kEmitText);
244-
- DrawBlobs(canvas, flags, bloberizer.Blobs(), point, node_id);
245-
+ // Bypass HarfBuzz text shaping for the html2svg Skia back-end
246-
+ auto blob = SkTextBlob::MakeFromString(
247-
+ StringView(run_info.run.ToStringView(), run_info.from, run_info.to - run_info.from).
248-
+ ToString().
249-
+ Utf8().
250-
+ c_str(),
251-
+ PrimaryFont()->
252-
+ PlatformData().
253-
+ CreateSkFont(false, &font_description_)
254-
+ );
269+
+ if (getenv("html2svg_svg_mode") != nullptr) {
270+
+ auto string = StringView(
271+
+ run_info.run.ToStringView(),
272+
+ run_info.from,
273+
+ run_info.to - run_info.from
274+
+ ).ToString().Utf8();
275+
+ auto* utf8 = string.c_str();
276+
+ size_t length = std::strlen(utf8) + 1;
277+
+ size_t buffer_length = SkBase64::Encode(utf8, length, nullptr);
278+
+ auto buffer = std::make_unique<char[]>(buffer_length + 1);
279+
+
280+
+ SkBase64::Encode(utf8, length, buffer.get());
281+
+ buffer[buffer_length] = '\0';
282+
+
283+
+ // Bypass HarfBuzz text shaping for the html2svg Skia back-end
284+
+ auto blob = SkTextBlob::MakeFromString(
285+
+ buffer.get(),
286+
+ PrimaryFont()->
287+
+ PlatformData().
288+
+ CreateSkFont(false, &font_description_)
289+
+ );
290+
+
291+
+ if (node_id != cc::kInvalidNodeId) {
292+
+ canvas->drawTextBlob(blob, point.x(), point.y(), node_id, flags);
293+
+ } else {
294+
+ canvas->drawTextBlob(blob, point.x(), point.y(), flags);
295+
+ }
255296
+
256-
+ if (node_id != cc::kInvalidNodeId) {
257-
+ canvas->drawTextBlob(blob, point.x(), point.y(), node_id, flags);
258-
+ } else {
259-
+ canvas->drawTextBlob(blob, point.x(), point.y(), flags);
297+
+ return;
260298
+ }
261-
}
262-
263-
void Font::DrawText(cc::PaintCanvas* canvas,
264-
@@ -253,13 +260,22 @@ void Font::DrawText(cc::PaintCanvas* canvas,
299+
+
300+
CachingWordShaper word_shaper(*this);
301+
ShapeResultBuffer buffer;
302+
word_shaper.FillResultBuffer(run_info, &buffer);
303+
@@ -253,6 +289,37 @@ void Font::DrawText(cc::PaintCanvas* canvas,
265304
if (ShouldSkipDrawing())
266305
return;
267306

268-
- ShapeResultBloberizer::FillGlyphsNG bloberizer(
269-
- GetFontDescription(), device_scale_factor > 1.0f, text_info.text,
270-
- text_info.from, text_info.to, text_info.shape_result,
271-
- draw_type == Font::DrawType::kGlyphsOnly
272-
- ? ShapeResultBloberizer::Type::kNormal
273-
- : ShapeResultBloberizer::Type::kEmitText);
274-
- DrawBlobs(canvas, flags, bloberizer.Blobs(), point, node_id);
275-
+ // Bypass HarfBuzz text shaping for the html2svg Skia back-end
276-
+ auto blob = SkTextBlob::MakeFromString(
277-
+ StringView(text_info.text, text_info.from, text_info.Length()).
278-
+ ToString().
279-
+ Utf8().
280-
+ c_str(),
281-
+ PrimaryFont()->
282-
+ PlatformData().
283-
+ CreateSkFont(false, &font_description_)
284-
+ );
307+
+ if (getenv("html2svg_svg_mode") != nullptr) {
308+
+ auto string = StringView(
309+
+ text_info.text,
310+
+ text_info.from,
311+
+ text_info.Length()
312+
+ ).ToString().Utf8();
313+
+ auto* utf8 = string.c_str();
314+
+ size_t length = std::strlen(utf8) + 1;
315+
+ size_t buffer_length = SkBase64::Encode(utf8, length, nullptr);
316+
+ auto buffer = std::make_unique<char[]>(buffer_length + 1);
317+
+
318+
+ SkBase64::Encode(utf8, length, buffer.get());
319+
+ buffer[buffer_length] = '\0';
320+
+
321+
+ // Bypass HarfBuzz text shaping for the html2svg Skia back-end
322+
+ auto blob = SkTextBlob::MakeFromString(
323+
+ buffer.get(),
324+
+ PrimaryFont()->
325+
+ PlatformData().
326+
+ CreateSkFont(false, &font_description_)
327+
+ );
285328
+
286-
+ if (node_id != cc::kInvalidNodeId) {
287-
+ canvas->drawTextBlob(blob, point.x(), point.y(), node_id, flags);
288-
+ } else {
289-
+ canvas->drawTextBlob(blob, point.x(), point.y(), flags);
329+
+ if (node_id != cc::kInvalidNodeId) {
330+
+ canvas->drawTextBlob(blob, point.x(), point.y(), node_id, flags);
331+
+ } else {
332+
+ canvas->drawTextBlob(blob, point.x(), point.y(), flags);
333+
+ }
334+
+
335+
+ return;
290336
+ }
291-
}
292-
293-
bool Font::DrawBidiText(cc::PaintCanvas* canvas,
337+
+
338+
ShapeResultBloberizer::FillGlyphsNG bloberizer(
339+
GetFontDescription(), device_scale_factor > 1.0f, text_info.text,
340+
text_info.from, text_info.to, text_info.shape_result,
294341
diff --git a/ui/gfx/linux/gpu_memory_buffer_support_x11.cc b/ui/gfx/linux/gpu_memory_buffer_support_x11.cc
295342
index a03a63e305027..4335b751e0cf4 100644
296343
--- a/ui/gfx/linux/gpu_memory_buffer_support_x11.cc

src/html2svg.ts

+5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ program
3737
.action(async (url, { full, wait, width, height, format }) => {
3838
const mode = getMode(format)
3939

40+
if (format === 'svg') {
41+
process.env.html2svg_svg_mode = 'true'
42+
}
43+
4044
app.dock?.hide()
45+
app.disableHardwareAcceleration()
4146
app.commandLine.appendSwitch('headless')
4247
app.commandLine.appendSwitch('no-sandbox')
4348
app.commandLine.appendSwitch('disable-gpu')

0 commit comments

Comments
 (0)