Skip to content

Commit 9f17862

Browse files
committed
HACK track the graphics state for each character
how does it vary over the page? Are there some characters that we should ignore?
1 parent 2d36273 commit 9f17862

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/pdf/reader/page_text_receiver.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ class PageTextReceiver
2525
def_delegators :@state, :set_line_cap_style, :set_line_dash, :set_line_join_style
2626
def_delegators :@state, :set_line_width, :set_miter_limit
2727

28+
# Graphics State Operators (colour)
29+
def_delegators :@state, :set_cmyk_color_for_stroking, :set_cmyk_color_for_nonstroking
30+
def_delegators :@state, :set_gray_color_for_stroking, :set_gray_color_for_nonstroking
31+
def_delegators :@state, :set_rgb_color_for_stroking, :set_rgb_color_for_nonstroking
32+
def_delegators :@state, :set_stroke_color_space, :set_nonstroke_color_space
33+
2834
# Matrix Operators
2935
def_delegators :@state, :concatenate_matrix
3036

@@ -113,7 +119,7 @@ def internal_show_text(string)
113119
th = 1
114120
scaled_glyph_width = glyph_width * @state.font_size * th
115121
unless utf8_chars == SPACE
116-
@characters << TextRun.new(newx, newy, scaled_glyph_width, @state.font_size, utf8_chars)
122+
@characters << TextRun.new(newx, newy, scaled_glyph_width, @state.font_size, utf8_chars, @state.clone_state)
117123
end
118124
@state.process_glyph_displacement(glyph_width, 0, utf8_chars == SPACE)
119125
end

lib/pdf/reader/text_run.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ class PDF::Reader
66
class TextRun
77
include Comparable
88

9-
attr_reader :x, :y, :width, :font_size, :text
9+
attr_reader :x, :y, :width, :font_size, :text, :state
1010

1111
alias :to_s :text
1212

13-
def initialize(x, y, width, font_size, text)
13+
def initialize(x, y, width, font_size, text, state)
1414
@x = x
1515
@y = y
1616
@width = width
1717
@font_size = font_size.floor
1818
@text = text
19+
@state = state
1920
end
2021

2122
# Allows collections of TextRun objects to be sorted. They will be sorted
@@ -50,14 +51,14 @@ def +(other)
5051
raise ArgumentError, "#{other} cannot be merged with this run" unless mergable?(other)
5152

5253
if (other.x - endx) <( font_size * 0.2)
53-
TextRun.new(x, y, other.endx - x, font_size, text + other.text)
54+
TextRun.new(x, y, other.endx - x, font_size, text + other.text, {})
5455
else
55-
TextRun.new(x, y, other.endx - x, font_size, "#{text} #{other.text}")
56+
TextRun.new(x, y, other.endx - x, font_size, "#{text} #{other.text}", {})
5657
end
5758
end
5859

5960
def inspect
60-
"#{text} w:#{width} f:#{font_size} @#{x},#{y}"
61+
"#{text} w:#{width} f:#{font_size} @#{x},#{y} #{@state.inspect}"
6162
end
6263

6364
private

0 commit comments

Comments
 (0)