forked from asciidoctor/asciidoctor-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves asciidoctor#353 add support for image float to converter
- add supports_float_wrapping? method to check if the following node supports wrapping around a float - add init_float_box method to set up float box - call init_float_box method in convert image handler if float attribute is set on image and next block supports float wrapping - add ink_paragraph_in_float_box to handle logic to render paragraph within float box - add image-float-gap key to theme to control space around image float - add extended converter example to docs to show how to enlist a code block in float wrapping - add support for :indent_paragraphs option to formatted text box - use image float in chronicles example to demonstrate
- Loading branch information
1 parent
524b8bd
commit e8a3b7c
Showing
15 changed files
with
1,104 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
docs/modules/extend/examples/pdf-converter-code-float-wrapping.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class PDFConverterCodeFloatWrapping < (Asciidoctor::Converter.for 'pdf') | ||
register_for 'pdf' | ||
|
||
def supports_float_wrapping? node | ||
%i(paragraph listing literal).include? node.context | ||
end | ||
|
||
def convert_code node | ||
return super unless (float_box = @float_box ||= nil) | ||
indent(float_box[:left] - bounds.left, bounds.width - float_box[:right]) { super } | ||
@float_box = nil unless page_number == float_box[:page] && cursor > float_box[:bottom] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
lib/asciidoctor/pdf/ext/prawn/formatted_text/indented_paragraph_wrap.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
module Prawn::Text::Formatted | ||
module IndentedParagraphWrap | ||
# Override Prawn::Text::Formatted::Box#wrap method to add support for :indent_paragraphs to (formatted_)text_box. | ||
def wrap array | ||
initialize_wrap array | ||
stop = nil | ||
until stop | ||
if (first_line_indent = @indent_paragraphs) && @printed_lines.empty? | ||
@width -= first_line_indent | ||
stop = @document.indent(first_line_indent) { wrap_and_print_line } | ||
@width += first_line_indent | ||
else | ||
stop = wrap_and_print_line | ||
end | ||
end | ||
@text = @printed_lines.join ?\n | ||
@everything_printed = @arranger.finished? | ||
@arranger.unconsumed | ||
end | ||
|
||
def wrap_and_print_line | ||
@line_wrap.wrap_line \ | ||
document: @document, | ||
kerning: @kerning, | ||
width: @width, | ||
arranger: @arranger, | ||
disable_wrap_by_char: @disable_wrap_by_char | ||
if enough_height_for_this_line? | ||
move_baseline_down | ||
print_line | ||
@single_line || @arranger.finished? | ||
else | ||
true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.