@@ -334,57 +334,6 @@ defmodule Mudbrick do
334
334
end )
335
335
end
336
336
337
- defp text_block ( doc , writes , top_level_opts ) do
338
- Enum . reduce ( writes , Mudbrick.TextBlock . new ( top_level_opts ) , fn
339
- { text , opts } , acc ->
340
- Mudbrick.TextBlock . write ( acc , text , fetch_font ( doc , opts ) )
341
-
342
- text , acc ->
343
- Mudbrick.TextBlock . write ( acc , text , [ ] )
344
- end )
345
- end
346
-
347
- @ spec cm_opts ( Mudbrick.Image . t ( ) , Image . image_options ( ) ) :: Mudbrick.ContentStream.Cm . options ( )
348
- defp cm_opts ( image , image_opts ) do
349
- scale =
350
- case image_opts [ :scale ] do
351
- { :auto , :auto } ->
352
- raise Mudbrick.Image.AutoScalingError ,
353
- "Auto scaling works with width or height, but not both."
354
-
355
- { w , :auto } ->
356
- ratio = w / image . width
357
- { w , image . height * ratio }
358
-
359
- { :auto , h } ->
360
- ratio = h / image . height
361
- { image . width * ratio , h }
362
-
363
- otherwise ->
364
- otherwise
365
- end
366
-
367
- Keyword . put ( image_opts , :scale , scale )
368
- end
369
-
370
- defp fetch_font ( doc , opts ) do
371
- default_font =
372
- case Map . values ( Document . root_page_tree ( doc ) . value . fonts ) do
373
- [ font ] -> font . value
374
- _ -> nil
375
- end
376
-
377
- Keyword . update ( opts , :font , default_font , fn user_identifier ->
378
- case Map . fetch ( Document . root_page_tree ( doc ) . value . fonts , user_identifier ) do
379
- { :ok , font } ->
380
- font . value
381
-
382
- :error ->
383
- raise Font.Unregistered , "Unregistered font: #{ user_identifier } "
384
- end
385
- end )
386
- end
387
-
388
337
@ doc """
389
338
Produce `iodata` from the current document.
390
339
"""
@@ -463,4 +412,55 @@ defmodule Mudbrick do
463
412
end )
464
413
|> finish ( & & 1 . value . contents )
465
414
end
415
+
416
+ defp text_block ( doc , writes , top_level_opts ) do
417
+ Enum . reduce ( writes , Mudbrick.TextBlock . new ( top_level_opts ) , fn
418
+ { text , opts } , acc ->
419
+ Mudbrick.TextBlock . write ( acc , text , fetch_font ( doc , opts ) )
420
+
421
+ text , acc ->
422
+ Mudbrick.TextBlock . write ( acc , text , [ ] )
423
+ end )
424
+ end
425
+
426
+ @ spec cm_opts ( Mudbrick.Image . t ( ) , Image . image_options ( ) ) :: Mudbrick.ContentStream.Cm . options ( )
427
+ defp cm_opts ( image , image_opts ) do
428
+ scale =
429
+ case image_opts [ :scale ] do
430
+ { :auto , :auto } ->
431
+ raise Mudbrick.Image.AutoScalingError ,
432
+ "Auto scaling works with width or height, but not both."
433
+
434
+ { w , :auto } ->
435
+ ratio = w / image . width
436
+ { w , image . height * ratio }
437
+
438
+ { :auto , h } ->
439
+ ratio = h / image . height
440
+ { image . width * ratio , h }
441
+
442
+ otherwise ->
443
+ otherwise
444
+ end
445
+
446
+ Keyword . put ( image_opts , :scale , scale )
447
+ end
448
+
449
+ defp fetch_font ( doc , opts ) do
450
+ default_font =
451
+ case Map . values ( Document . root_page_tree ( doc ) . value . fonts ) do
452
+ [ font ] -> font . value
453
+ _ -> nil
454
+ end
455
+
456
+ Keyword . update ( opts , :font , default_font , fn user_identifier ->
457
+ case Map . fetch ( Document . root_page_tree ( doc ) . value . fonts , user_identifier ) do
458
+ { :ok , font } ->
459
+ font . value
460
+
461
+ :error ->
462
+ raise Font.Unregistered , "Unregistered font: #{ user_identifier } "
463
+ end
464
+ end )
465
+ end
466
466
end
0 commit comments