Renderer.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Copyright (c) 2021-2022, Matthew Olsson <mattco@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Utf8View.h>
  7. #include <LibPDF/CommonNames.h>
  8. #include <LibPDF/Fonts.h>
  9. #include <LibPDF/Renderer.h>
  10. #define RENDERER_HANDLER(name) \
  11. PDFErrorOr<void> Renderer::handle_##name([[maybe_unused]] Vector<Value> const& args)
  12. #define RENDERER_TODO(name) \
  13. RENDERER_HANDLER(name) \
  14. { \
  15. dbgln("[PDF::Renderer] Unsupported draw operation " #name); \
  16. TODO(); \
  17. }
  18. namespace PDF {
  19. PDFErrorOr<void> Renderer::render(Document& document, Page const& page, RefPtr<Gfx::Bitmap> bitmap)
  20. {
  21. return Renderer(document, page, bitmap).render();
  22. }
  23. Renderer::Renderer(RefPtr<Document> document, Page const& page, RefPtr<Gfx::Bitmap> bitmap)
  24. : m_document(document)
  25. , m_bitmap(bitmap)
  26. , m_page(page)
  27. , m_painter(*bitmap)
  28. {
  29. auto media_box = m_page.media_box;
  30. Gfx::AffineTransform userspace_matrix;
  31. userspace_matrix.translate(media_box.lower_left_x, media_box.lower_left_y);
  32. float width = media_box.upper_right_x - media_box.lower_left_x;
  33. float height = media_box.upper_right_y - media_box.lower_left_y;
  34. float scale_x = static_cast<float>(bitmap->width()) / width;
  35. float scale_y = static_cast<float>(bitmap->height()) / height;
  36. userspace_matrix.scale(scale_x, scale_y);
  37. // PDF user-space coordinate y axis increases from bottom to top, so we have to
  38. // insert a horizontal reflection about the vertical midpoint into our transformation
  39. // matrix
  40. static Gfx::AffineTransform horizontal_reflection_matrix = { 1, 0, 0, -1, 0, 0 };
  41. userspace_matrix.multiply(horizontal_reflection_matrix);
  42. userspace_matrix.translate(0.0f, -height);
  43. m_graphics_state_stack.append(GraphicsState { userspace_matrix });
  44. m_bitmap->fill(Gfx::Color::NamedColor::White);
  45. }
  46. PDFErrorOr<void> Renderer::render()
  47. {
  48. // Use our own vector, as the /Content can be an array with multiple
  49. // streams which gets concatenated
  50. // FIXME: Text operators are supposed to only have effects on the current
  51. // stream object. Do the text operators treat this concatenated stream
  52. // as one stream or multiple?
  53. ByteBuffer byte_buffer;
  54. if (m_page.contents->is<ArrayObject>()) {
  55. auto contents = m_page.contents->cast<ArrayObject>();
  56. for (auto& ref : *contents) {
  57. auto bytes = TRY(m_document->resolve_to<StreamObject>(ref))->bytes();
  58. byte_buffer.append(bytes.data(), bytes.size());
  59. }
  60. } else {
  61. auto bytes = m_page.contents->cast<StreamObject>()->bytes();
  62. byte_buffer.append(bytes.data(), bytes.size());
  63. }
  64. auto commands = TRY(Parser::parse_graphics_commands(m_document, byte_buffer));
  65. for (auto& command : commands)
  66. TRY(handle_command(command));
  67. return {};
  68. }
  69. PDFErrorOr<void> Renderer::handle_command(Command const& command)
  70. {
  71. switch (command.command_type()) {
  72. #define V(name, snake_name, symbol) \
  73. case CommandType::name: \
  74. TRY(handle_##snake_name(command.arguments())); \
  75. break;
  76. ENUMERATE_COMMANDS(V)
  77. #undef V
  78. case CommandType::TextNextLineShowString:
  79. TRY(handle_text_next_line_show_string(command.arguments()));
  80. break;
  81. case CommandType::TextNextLineShowStringSetSpacing:
  82. TRY(handle_text_next_line_show_string_set_spacing(command.arguments()));
  83. break;
  84. }
  85. return {};
  86. }
  87. RENDERER_HANDLER(save_state)
  88. {
  89. m_graphics_state_stack.append(state());
  90. return {};
  91. }
  92. RENDERER_HANDLER(restore_state)
  93. {
  94. m_graphics_state_stack.take_last();
  95. return {};
  96. }
  97. RENDERER_HANDLER(concatenate_matrix)
  98. {
  99. Gfx::AffineTransform new_transform(
  100. args[0].to_float(),
  101. args[1].to_float(),
  102. args[2].to_float(),
  103. args[3].to_float(),
  104. args[4].to_float(),
  105. args[5].to_float());
  106. state().ctm.multiply(new_transform);
  107. m_text_rendering_matrix_is_dirty = true;
  108. return {};
  109. }
  110. RENDERER_HANDLER(set_line_width)
  111. {
  112. state().line_width = args[0].to_float();
  113. return {};
  114. }
  115. RENDERER_HANDLER(set_line_cap)
  116. {
  117. state().line_cap_style = static_cast<LineCapStyle>(args[0].get<int>());
  118. return {};
  119. }
  120. RENDERER_HANDLER(set_line_join)
  121. {
  122. state().line_join_style = static_cast<LineJoinStyle>(args[0].get<int>());
  123. return {};
  124. }
  125. RENDERER_HANDLER(set_miter_limit)
  126. {
  127. state().miter_limit = args[0].to_float();
  128. return {};
  129. }
  130. RENDERER_HANDLER(set_dash_pattern)
  131. {
  132. auto dash_array = MUST(m_document->resolve_to<ArrayObject>(args[0]));
  133. Vector<int> pattern;
  134. for (auto& element : *dash_array)
  135. pattern.append(element.get<int>());
  136. state().line_dash_pattern = LineDashPattern { pattern, args[1].get<int>() };
  137. return {};
  138. }
  139. RENDERER_TODO(set_color_rendering_intent)
  140. RENDERER_TODO(set_flatness_tolerance)
  141. RENDERER_HANDLER(set_graphics_state_from_dict)
  142. {
  143. VERIFY(m_page.resources->contains(CommonNames::ExtGState));
  144. auto dict_name = MUST(m_document->resolve_to<NameObject>(args[0]))->name();
  145. auto ext_gstate_dict = MUST(m_page.resources->get_dict(m_document, CommonNames::ExtGState));
  146. auto target_dict = MUST(ext_gstate_dict->get_dict(m_document, dict_name));
  147. TRY(set_graphics_state_from_dict(target_dict));
  148. return {};
  149. }
  150. RENDERER_HANDLER(path_move)
  151. {
  152. m_current_path.move_to(map(args[0].to_float(), args[1].to_float()));
  153. return {};
  154. }
  155. RENDERER_HANDLER(path_line)
  156. {
  157. VERIFY(!m_current_path.segments().is_empty());
  158. m_current_path.line_to(map(args[0].to_float(), args[1].to_float()));
  159. return {};
  160. }
  161. RENDERER_TODO(path_cubic_bezier_curve)
  162. RENDERER_TODO(path_cubic_bezier_curve_no_first_control)
  163. RENDERER_TODO(path_cubic_bezier_curve_no_second_control)
  164. RENDERER_HANDLER(path_close)
  165. {
  166. m_current_path.close();
  167. return {};
  168. }
  169. RENDERER_HANDLER(path_append_rect)
  170. {
  171. auto pos = map(args[0].to_float(), args[1].to_float());
  172. auto size = map(Gfx::FloatSize { args[2].to_float(), args[3].to_float() });
  173. m_current_path.move_to(pos);
  174. m_current_path.line_to({ pos.x() + size.width(), pos.y() });
  175. m_current_path.line_to({ pos.x() + size.width(), pos.y() + size.height() });
  176. m_current_path.line_to({ pos.x(), pos.y() + size.height() });
  177. m_current_path.close();
  178. return {};
  179. }
  180. RENDERER_HANDLER(path_stroke)
  181. {
  182. m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width);
  183. m_current_path.clear();
  184. return {};
  185. }
  186. RENDERER_HANDLER(path_close_and_stroke)
  187. {
  188. m_current_path.close();
  189. TRY(handle_path_stroke(args));
  190. return {};
  191. }
  192. RENDERER_HANDLER(path_fill_nonzero)
  193. {
  194. m_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::Nonzero);
  195. m_current_path.clear();
  196. return {};
  197. }
  198. RENDERER_HANDLER(path_fill_nonzero_deprecated)
  199. {
  200. TRY(handle_path_fill_nonzero(args));
  201. return {};
  202. }
  203. RENDERER_HANDLER(path_fill_evenodd)
  204. {
  205. m_painter.fill_path(m_current_path, state().paint_color, Gfx::Painter::WindingRule::EvenOdd);
  206. m_current_path.clear();
  207. return {};
  208. }
  209. RENDERER_HANDLER(path_fill_stroke_nonzero)
  210. {
  211. m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width);
  212. TRY(handle_path_fill_nonzero(args));
  213. return {};
  214. }
  215. RENDERER_HANDLER(path_fill_stroke_evenodd)
  216. {
  217. m_painter.stroke_path(m_current_path, state().stroke_color, state().line_width);
  218. TRY(handle_path_fill_evenodd(args));
  219. return {};
  220. }
  221. RENDERER_HANDLER(path_close_fill_stroke_nonzero)
  222. {
  223. m_current_path.close();
  224. TRY(handle_path_fill_stroke_nonzero(args));
  225. return {};
  226. }
  227. RENDERER_HANDLER(path_close_fill_stroke_evenodd)
  228. {
  229. m_current_path.close();
  230. TRY(handle_path_fill_stroke_evenodd(args));
  231. return {};
  232. }
  233. RENDERER_HANDLER(path_end)
  234. {
  235. return {};
  236. }
  237. RENDERER_HANDLER(path_intersect_clip_nonzero)
  238. {
  239. // FIXME: Support arbitrary path clipping in the painter and utilize that here
  240. auto bounding_box = map(m_current_path.bounding_box());
  241. m_painter.add_clip_rect(bounding_box.to_type<int>());
  242. return {};
  243. }
  244. RENDERER_HANDLER(path_intersect_clip_evenodd)
  245. {
  246. // FIXME: Support arbitrary path clipping in the painter and utilize that here
  247. auto bounding_box = map(m_current_path.bounding_box());
  248. m_painter.add_clip_rect(bounding_box.to_type<int>());
  249. return {};
  250. }
  251. RENDERER_HANDLER(text_begin)
  252. {
  253. m_text_matrix = Gfx::AffineTransform();
  254. m_text_line_matrix = Gfx::AffineTransform();
  255. return {};
  256. }
  257. RENDERER_HANDLER(text_end)
  258. {
  259. // FIXME: Do we need to do anything here?
  260. return {};
  261. }
  262. RENDERER_HANDLER(text_set_char_space)
  263. {
  264. text_state().character_spacing = args[0].to_float();
  265. return {};
  266. }
  267. RENDERER_HANDLER(text_set_word_space)
  268. {
  269. text_state().word_spacing = args[0].to_float();
  270. return {};
  271. }
  272. RENDERER_HANDLER(text_set_horizontal_scale)
  273. {
  274. m_text_rendering_matrix_is_dirty = true;
  275. text_state().horizontal_scaling = args[0].to_float() / 100.0f;
  276. return {};
  277. }
  278. RENDERER_HANDLER(text_set_leading)
  279. {
  280. text_state().leading = args[0].to_float();
  281. return {};
  282. }
  283. RENDERER_HANDLER(text_set_font)
  284. {
  285. auto target_font_name = MUST(m_document->resolve_to<NameObject>(args[0]))->name();
  286. auto fonts_dictionary = MUST(m_page.resources->get_dict(m_document, CommonNames::Font));
  287. auto font_dictionary = MUST(fonts_dictionary->get_dict(m_document, target_font_name));
  288. auto font = TRY(PDFFont::create(m_document, font_dictionary));
  289. text_state().font = font;
  290. // FIXME: We do not yet have the standard 14 fonts, as some of them are not open fonts,
  291. // so we just use LiberationSerif for everything
  292. auto font_name = MUST(font_dictionary->get_name(m_document, CommonNames::BaseFont))->name().to_lowercase();
  293. auto font_view = font_name.view();
  294. bool is_bold = font_view.contains("bold");
  295. bool is_italic = font_view.contains("italic");
  296. String font_variant;
  297. if (is_bold && is_italic) {
  298. font_variant = "BoldItalic";
  299. } else if (is_bold) {
  300. font_variant = "Bold";
  301. } else if (is_italic) {
  302. font_variant = "Italic";
  303. } else {
  304. font_variant = "Regular";
  305. }
  306. text_state().font_size = args[1].to_float();
  307. text_state().font_variant = font_variant;
  308. m_text_rendering_matrix_is_dirty = true;
  309. return {};
  310. }
  311. RENDERER_HANDLER(text_set_rendering_mode)
  312. {
  313. text_state().rendering_mode = static_cast<TextRenderingMode>(args[0].get<int>());
  314. return {};
  315. }
  316. RENDERER_HANDLER(text_set_rise)
  317. {
  318. m_text_rendering_matrix_is_dirty = true;
  319. text_state().rise = args[0].to_float();
  320. return {};
  321. }
  322. RENDERER_HANDLER(text_next_line_offset)
  323. {
  324. Gfx::AffineTransform transform(1.0f, 0.0f, 0.0f, 1.0f, args[0].to_float(), args[1].to_float());
  325. transform.multiply(m_text_line_matrix);
  326. m_text_matrix = transform;
  327. m_text_line_matrix = transform;
  328. m_text_rendering_matrix_is_dirty = true;
  329. return {};
  330. }
  331. RENDERER_HANDLER(text_next_line_and_set_leading)
  332. {
  333. text_state().leading = -args[1].to_float();
  334. TRY(handle_text_next_line_offset(args));
  335. return {};
  336. }
  337. RENDERER_HANDLER(text_set_matrix_and_line_matrix)
  338. {
  339. Gfx::AffineTransform new_transform(
  340. args[0].to_float(),
  341. args[1].to_float(),
  342. args[2].to_float(),
  343. args[3].to_float(),
  344. args[4].to_float(),
  345. args[5].to_float());
  346. m_text_line_matrix = new_transform;
  347. m_text_matrix = new_transform;
  348. m_text_rendering_matrix_is_dirty = true;
  349. return {};
  350. }
  351. RENDERER_HANDLER(text_next_line)
  352. {
  353. TRY(handle_text_next_line_offset({ 0.0f, -text_state().leading }));
  354. return {};
  355. }
  356. RENDERER_HANDLER(text_show_string)
  357. {
  358. auto text = MUST(m_document->resolve_to<StringObject>(args[0]))->string();
  359. show_text(text);
  360. return {};
  361. }
  362. RENDERER_HANDLER(text_next_line_show_string)
  363. {
  364. TRY(handle_text_next_line(args));
  365. TRY(handle_text_show_string(args));
  366. return {};
  367. }
  368. RENDERER_TODO(text_next_line_show_string_set_spacing)
  369. RENDERER_HANDLER(text_show_string_array)
  370. {
  371. auto elements = MUST(m_document->resolve_to<ArrayObject>(args[0]))->elements();
  372. float next_shift = 0.0f;
  373. for (auto& element : elements) {
  374. if (element.has<int>()) {
  375. next_shift = element.get<int>();
  376. } else if (element.has<float>()) {
  377. next_shift = element.get<float>();
  378. } else {
  379. auto str = element.get<NonnullRefPtr<Object>>()->cast<StringObject>()->string();
  380. show_text(str, next_shift);
  381. }
  382. }
  383. return {};
  384. }
  385. RENDERER_TODO(type3_font_set_glyph_width)
  386. RENDERER_TODO(type3_font_set_glyph_width_and_bbox)
  387. RENDERER_HANDLER(set_stroking_space)
  388. {
  389. state().stroke_color_space = TRY(get_color_space(args[0]));
  390. VERIFY(state().stroke_color_space);
  391. return {};
  392. }
  393. RENDERER_HANDLER(set_painting_space)
  394. {
  395. state().paint_color_space = TRY(get_color_space(args[0]));
  396. VERIFY(state().paint_color_space);
  397. return {};
  398. }
  399. RENDERER_HANDLER(set_stroking_color)
  400. {
  401. state().stroke_color = state().stroke_color_space->color(args);
  402. return {};
  403. }
  404. RENDERER_HANDLER(set_stroking_color_extended)
  405. {
  406. // FIXME: Handle Pattern color spaces
  407. auto last_arg = args.last();
  408. if (last_arg.has<NonnullRefPtr<Object>>() && last_arg.get<NonnullRefPtr<Object>>()->is<NameObject>())
  409. TODO();
  410. state().stroke_color = state().stroke_color_space->color(args);
  411. return {};
  412. }
  413. RENDERER_HANDLER(set_painting_color)
  414. {
  415. state().paint_color = state().paint_color_space->color(args);
  416. return {};
  417. }
  418. RENDERER_HANDLER(set_painting_color_extended)
  419. {
  420. // FIXME: Handle Pattern color spaces
  421. auto last_arg = args.last();
  422. if (last_arg.has<NonnullRefPtr<Object>>() && last_arg.get<NonnullRefPtr<Object>>()->is<NameObject>())
  423. TODO();
  424. state().paint_color = state().paint_color_space->color(args);
  425. return {};
  426. }
  427. RENDERER_HANDLER(set_stroking_color_and_space_to_gray)
  428. {
  429. state().stroke_color_space = DeviceGrayColorSpace::the();
  430. state().stroke_color = state().stroke_color_space->color(args);
  431. return {};
  432. }
  433. RENDERER_HANDLER(set_painting_color_and_space_to_gray)
  434. {
  435. state().paint_color_space = DeviceGrayColorSpace::the();
  436. state().paint_color = state().paint_color_space->color(args);
  437. return {};
  438. }
  439. RENDERER_HANDLER(set_stroking_color_and_space_to_rgb)
  440. {
  441. state().stroke_color_space = DeviceRGBColorSpace::the();
  442. state().stroke_color = state().stroke_color_space->color(args);
  443. return {};
  444. }
  445. RENDERER_HANDLER(set_painting_color_and_space_to_rgb)
  446. {
  447. state().paint_color_space = DeviceRGBColorSpace::the();
  448. state().paint_color = state().paint_color_space->color(args);
  449. return {};
  450. }
  451. RENDERER_HANDLER(set_stroking_color_and_space_to_cmyk)
  452. {
  453. state().stroke_color_space = DeviceCMYKColorSpace::the();
  454. state().stroke_color = state().stroke_color_space->color(args);
  455. return {};
  456. }
  457. RENDERER_HANDLER(set_painting_color_and_space_to_cmyk)
  458. {
  459. state().paint_color_space = DeviceCMYKColorSpace::the();
  460. state().paint_color = state().paint_color_space->color(args);
  461. return {};
  462. }
  463. RENDERER_TODO(shade)
  464. RENDERER_TODO(inline_image_begin)
  465. RENDERER_TODO(inline_image_begin_data)
  466. RENDERER_TODO(inline_image_end)
  467. RENDERER_TODO(paint_xobject)
  468. RENDERER_HANDLER(marked_content_point)
  469. {
  470. // nop
  471. return {};
  472. }
  473. RENDERER_HANDLER(marked_content_designate)
  474. {
  475. // nop
  476. return {};
  477. }
  478. RENDERER_HANDLER(marked_content_begin)
  479. {
  480. // nop
  481. return {};
  482. }
  483. RENDERER_HANDLER(marked_content_begin_with_property_list)
  484. {
  485. // nop
  486. return {};
  487. }
  488. RENDERER_HANDLER(marked_content_end)
  489. {
  490. // nop
  491. return {};
  492. }
  493. RENDERER_TODO(compatibility_begin)
  494. RENDERER_TODO(compatibility_end)
  495. template<typename T>
  496. Gfx::Point<T> Renderer::map(T x, T y) const
  497. {
  498. auto mapped = state().ctm.map(Gfx::Point<T> { x, y });
  499. return { mapped.x(), static_cast<T>(m_bitmap->height()) - mapped.y() };
  500. }
  501. template<typename T>
  502. Gfx::Size<T> Renderer::map(Gfx::Size<T> size) const
  503. {
  504. return state().ctm.map(size);
  505. }
  506. template<typename T>
  507. Gfx::Rect<T> Renderer::map(Gfx::Rect<T> rect) const
  508. {
  509. return state().ctm.map(rect);
  510. }
  511. PDFErrorOr<void> Renderer::set_graphics_state_from_dict(NonnullRefPtr<DictObject> dict)
  512. {
  513. if (dict->contains(CommonNames::LW))
  514. TRY(handle_set_line_width({ dict->get_value(CommonNames::LW) }));
  515. if (dict->contains(CommonNames::LC))
  516. TRY(handle_set_line_cap({ dict->get_value(CommonNames::LC) }));
  517. if (dict->contains(CommonNames::LJ))
  518. TRY(handle_set_line_join({ dict->get_value(CommonNames::LJ) }));
  519. if (dict->contains(CommonNames::ML))
  520. TRY(handle_set_miter_limit({ dict->get_value(CommonNames::ML) }));
  521. if (dict->contains(CommonNames::D)) {
  522. auto array = MUST(dict->get_array(m_document, CommonNames::D));
  523. TRY(handle_set_dash_pattern(array->elements()));
  524. }
  525. if (dict->contains(CommonNames::FL))
  526. TRY(handle_set_flatness_tolerance({ dict->get_value(CommonNames::FL) }));
  527. return {};
  528. }
  529. void Renderer::show_text(String const& string, float shift)
  530. {
  531. auto& text_rendering_matrix = calculate_text_rendering_matrix();
  532. auto font_size = static_cast<int>(text_rendering_matrix.x_scale() * text_state().font_size);
  533. auto font = Gfx::FontDatabase::the().get(text_state().font_family, text_state().font_variant, font_size);
  534. VERIFY(font);
  535. auto glyph_position = text_rendering_matrix.map(Gfx::FloatPoint { 0.0f, 0.0f });
  536. // Account for the reversed font baseline
  537. glyph_position.set_y(glyph_position.y() - static_cast<float>(font->baseline()));
  538. auto original_position = glyph_position;
  539. for (auto char_code : string.bytes()) {
  540. auto code_point = text_state().font->char_code_to_code_point(char_code);
  541. if (code_point != 0x20)
  542. m_painter.draw_glyph(glyph_position.to_type<int>(), code_point, *font, state().paint_color);
  543. auto glyph_width = static_cast<float>(font->glyph_width(code_point));
  544. auto tx = (glyph_width - shift / 1000.0f);
  545. tx += text_state().character_spacing;
  546. if (code_point == ' ')
  547. tx += text_state().word_spacing;
  548. tx *= text_state().horizontal_scaling;
  549. glyph_position += { tx, 0.0f };
  550. }
  551. // Update text matrix
  552. auto delta_x = glyph_position.x() - original_position.x();
  553. m_text_rendering_matrix_is_dirty = true;
  554. m_text_matrix = Gfx::AffineTransform(1, 0, 0, 1, delta_x, 0).multiply(m_text_matrix);
  555. }
  556. PDFErrorOr<NonnullRefPtr<ColorSpace>> Renderer::get_color_space(Value const& value)
  557. {
  558. auto name = value.get<NonnullRefPtr<Object>>()->cast<NameObject>()->name();
  559. return TRY(ColorSpace::create(m_document, name, m_page));
  560. }
  561. Gfx::AffineTransform const& Renderer::calculate_text_rendering_matrix()
  562. {
  563. if (m_text_rendering_matrix_is_dirty) {
  564. m_text_rendering_matrix = Gfx::AffineTransform(
  565. text_state().horizontal_scaling,
  566. 0.0f,
  567. 0.0f,
  568. 1.0f,
  569. 0.0f,
  570. text_state().rise);
  571. m_text_rendering_matrix.multiply(state().ctm);
  572. m_text_rendering_matrix.multiply(m_text_matrix);
  573. m_text_rendering_matrix_is_dirty = false;
  574. }
  575. return m_text_rendering_matrix;
  576. }
  577. }