class Prawn::Text::Formatted::LineWrap

Constants

ALNUM_PATTERN

英数字・キリル文字・ギリシャ文字・コンマ・ピリオド の繰り返し

ATMARKS
DASH_PATTERN

各種ダッシュ。種類が異なってもよい。

EXTRA_SPLITTABLE_CHAR
LEADER_PATTERN

同一種類のリーダーの2個繰り返し

PROHIBIT_LINE_BREAK_AFTER

行末禁則

PROHIBIT_LINE_BREAK_AFTER_CHARS
PROHIBIT_LINE_BREAK_BEFORE

行頭禁則

PROHIBIT_LINE_BREAK_BEFORE_CHARS
UNDERSCORES

Public Class Methods

or_rgexp( chars ) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 27
def self.or_rgexp( chars )
  s = chars.chars.map{ |e| Regexp.escape(e) }.join
  /[#{s}]/
end

Public Instance Methods

end_of_the_line_reached(segment) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 105
def end_of_the_line_reached(segment)
  if !@fragment_output.strip.empty? && !segment.strip.empty?
    @line_contains_more_than_one_word = true
  end

  update_line_status_based_on_last_output
  unless @line_contains_more_than_one_word
    wrap_by_char(segment)
  end
  @line_full = true
end
get_last_token_of(text) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 121
def get_last_token_of(text)
  if text
    tokenize(text).last
  else
    ""
  end
end
initialize_line(options) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 22
def initialize_line(options)
  original_initialize_line(options)
  @disable_wrap_by_char = true
end
Also aliased as: original_initialize_line
original_initialize_line(options)
Alias for: initialize_line
remember_this_fragment_for_backward_looking_ops() click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 135
def remember_this_fragment_for_backward_looking_ops
  @previous_fragment = @fragment_output.dup
  pf = @previous_fragment
  @previous_fragment_ended_with_breakable = text_ended_with_breakable(pf)
  @previous_fragment_output_without_last_word = get_last_token_of pf
end
split_pattern(s) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 71
def split_pattern(s)
  case s
  when PROHIBIT_LINE_BREAK_BEFORE,
       PROHIBIT_LINE_BREAK_AFTER,
       DASH_PATTERN,
       LEADER_PATTERN,
       ALNUM_PATTERN
    false
  when /[\-\s\p{Space}\u{200B}\u{00ad}]/, # 空白(200b は、ゼロ幅空白。00ad は、soft-hyphen)
       /[\p{Hiragana}\p{Katakana}#{EXTRA_SPLITTABLE_CHAR}\p{Han}]/, # 日本語等
       /[\p{Initial_Punctuation}\p{Open_Punctuation}]/, # 開き括弧等
       /[\p{Terminal_Punctuation}\p{Close_Punctuation}\p{Final_Punctuation}]/ # 閉じ括弧等
    true
  else
    false
  end
end
text_ended_with_breakable( text ) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 117
def text_ended_with_breakable( text )
  true
end
tokenize(fragment) click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 89
def tokenize(fragment)
  if /ち/===fragment
    x=0
  end
  fragment.size.times.with_object(["".clone]) do |ix,s|
    cur = fragment[ix]
    if s.last.empty?
      s.last << cur
    elsif split_pattern(s.last[-1]+cur)
      s.push cur
    else
      s.last << cur
    end
  end
end
update_line_status_based_on_last_output() click to toggle source
# File lib/asciidoctor/nabetani/prawn-linewrap-ja.rb, line 129
def update_line_status_based_on_last_output
  if 1<tokenize(@fragment_output).size
    @line_contains_more_than_one_word = true
  end
end