Class: ODDB::FiParse::FachinfoTextHandler

Inherits:
Rwv2::TextHandler
  • Object
show all
Defined in:
ext/fiparse/src/fachinfo_doc.rb

Constant Summary collapse

CHARS_PER_INCH =
14
TWIPS_PER_CHAR =
(72*20 / CHARS_PER_INCH ).to_i
DEFAULT_TAB_WIDTH =
720

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFachinfoTextHandler

Returns a new instance of FachinfoTextHandler.



200
201
202
203
204
205
206
# File 'ext/fiparse/src/fachinfo_doc.rb', line 200

def initialize
	@writers = []
     @table_handler = FachinfoTableHandler.new
     @cutoff_fontsize = 40
     @max_fontsize = 0
     @iconv = Iconv.new('UTF-8', 'UTF-16')
end

Instance Attribute Details

#cutoff_fontsizeObject

Returns the value of attribute cutoff_fontsize.



199
200
201
# File 'ext/fiparse/src/fachinfo_doc.rb', line 199

def cutoff_fontsize
  @cutoff_fontsize
end

#max_fontsizeObject (readonly)

Returns the value of attribute max_fontsize.



198
199
200
# File 'ext/fiparse/src/fachinfo_doc.rb', line 198

def max_fontsize
  @max_fontsize
end

#table_handlerObject (readonly)

Returns the value of attribute table_handler.



198
199
200
# File 'ext/fiparse/src/fachinfo_doc.rb', line 198

def table_handler
  @table_handler
end

#writersObject (readonly)

Returns the value of attribute writers.



198
199
200
# File 'ext/fiparse/src/fachinfo_doc.rb', line 198

def writers
  @writers
end

Instance Method Details

#_run_of_text(text, char_props) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'ext/fiparse/src/fachinfo_doc.rb', line 235

def _run_of_text(text, char_props)
     #puts sprintf("%2i %s -> %s",char_props.fontsize, same_font?(@current_char_props, char_props), text[0,10])
	if(!same_font?(@current_char_props, char_props))
		if(char_props.fontsize >= @cutoff_fontsize \
          && (@writer.nil? || @writer.complete?))
         @writer = FachinfoDocWriter.new
         @table_handler.writer = @writer
         @writer.cutoff_fontsize = @cutoff_fontsize
         @writers.push(@writer)
       end
       @max_fontsize = [@max_fontsize, char_props.fontsize].max
	end
	if(/^-{5,}$/u.match(text))
		@preformatted = text.length
	elsif(@preformatted && (text.length > @preformatted))
		@preformatted = nil
		@current_char_props = nil
	elsif(@preformatted \
		&& !same_font?(@current_char_props, char_props))
		@preformatted = nil
	end
	unless(@writer.nil?)
		unless(same_font?(@current_char_props, char_props))
			@writer.new_font(char_props, text)
		end
		if(@preformatted)
			@writer.send_literal_data(expand_tabs(text))
       #elsif(@table_handler.in_table?)
       #  @table_handler.send_flowing_data(text)
		else
			@writer.send_flowing_data(text)
		end
	end
	@current_char_props = char_props
end

#paragraph_endObject



207
208
209
210
211
212
213
214
215
216
217
# File 'ext/fiparse/src/fachinfo_doc.rb', line 207

def paragraph_end
	unless(@writer.nil?)
		if(@preformatted)
			@writer.send_literal_data("\n")
		else
			@current_char_props = nil
			@writer.send_flowing_data("\n")
			@writer.send_line_break
		end
	end
end

#paragraph_start(paragraph_props) ⇒ Object



218
219
220
221
222
223
224
225
# File 'ext/fiparse/src/fachinfo_doc.rb', line 218

def paragraph_start(paragraph_props)
	tabs = paragraph_props.tab_descriptors
	unless(tabs.any? { |tab| tab.position > 9000})
		@tabs = tabs
	else
		@tabs = []
	end
end

#run_of_text(text, char_props) ⇒ Object



226
227
228
229
230
231
232
233
234
# File 'ext/fiparse/src/fachinfo_doc.rb', line 226

def run_of_text(text, char_props)
  text = @iconv.iconv(text)
  text.split(/\v/u).each_with_index { |run, idx|
    if(idx > 0 && @writer)
      @writer.send_line_break
    end
    _run_of_text(run, char_props)
  }
end