Class: ODDB::FiPDF::FachinfoWriter
- Defined in:
- ext/fipdf/src/fachinfo_writer.rb
Direct Known Subclasses
Constant Summary collapse
- ALPHA_GAP =
5
- ALPHA_FONT =
"Helvetica-Bold"
- COLOR_DRUG_NAME_BG =
{ :generic => [0.168, 0.640, 0.461], :original => [1, 0, 0], :unknown => [0.667, 0.667, 0.667], }
- COLOR_DRUG_NAME_INDEX =
{ :generic => [0, 0.4 , 0], :original => [1, 0, 0], :unknown => [0, 0, 0], }
- COLOR_DRUG_NAME_FNT =
{ :generic => [1, 1, 1], :original => [1, 1, 1], :unknown => [0, 0, 0], }
- COLOR_BG =
{ :generic => [0.635, 1, 0.627], :original => [1, 0.700, 0.700], :unknown => [1, 1, 1], }
- COLOR_STD =
[0, 0, 0]
- COLUMNS_FI =
3
- COLUMNS_INDEX =
4
- COLUMN_GAP_FI =
10
- COLUMN_GAP_INDEX =
10
- FIXED_WIDTH_FONT =
"Courier"
- FLIC_YPOS =
825
- FONT_SIZE_ALPHA =
16
- FONT_SIZE_FLIC =
10
- FONT_SIZE_FIXED_WIDTH =
5.3
- FONT_SIZE_TITLE =
14
- GRAY_DRUG_NAME_BG =
{ :generic => [0.7, 0.7, 0.7], :original => [0, 0, 0], :unknown => [0.3, 0.3, 0.3], }
- ISO_8859_1_DIFFERENCES =
{ 160 => 'space', 164 => 'currency', 214 => 'Odieresis', 166 => 'brokenbar', 215 => 'multiply', 168 => 'dieresis', 216 => 'Oslash', 169 => 'copyright', 217 => 'Ugrave', 170 => 'ordfeminine', 218 => 'Uacute', 172 => 'logicalnot', 219 => 'Ucircumflex', 173 => 'endash', 220 => 'Udieresis', 174 => 'registered', 221 => 'Yacute', 175 => 'macron', 222 => 'Thorn', 176 => 'degree', 223 => 'germandbls', 177 => 'plusminus', 224 => 'agrave', 178 => 'twosuperior', 225 => 'aacute', 179 => 'threesuperior', 226 => 'acircumflex', 180 => 'acute', 227 => 'atilde', 181 => 'mu', 228 => 'adieresis', 184 => 'cedilla', 229 => 'aring', 185 => 'onesuperior', 230 => 'ae', 186 => 'ordmasculine', 231 => 'ccedilla', 188 => 'onequarter', 232 => 'egrave', 189 => 'onehalf', 233 => 'eacute', 190 => 'threequarters', 234 => 'ecircumflex', 192 => 'Agrave', 235 => 'edieresis', 193 => 'Aacute', 236 => 'igrave', 194 => 'Acircumflex', 237 => 'iacute', 195 => 'Atilde', 238 => 'icircumflex', 196 => 'Adieresis', 239 => 'idieresis', 197 => 'Aring', 240 => 'eth', 198 => 'AE', 241 => 'ntilde', 199 => 'Ccedilla', 242 => 'ograve', 200 => 'Egrave', 243 => 'oacute', 201 => 'Eacute', 244 => 'ocircumflex', 202 => 'Ecircumflex', 245 => 'otilde', 203 => 'Edieresis', 246 => 'odieresis', 204 => 'Igrave', 247 => 'divide', 205 => 'Iacute', 248 => 'oslash', 206 => 'Icircumflex', 249 => 'ugrave', 207 => 'Idieresis', 250 => 'uacute', 208 => 'Eth', 251 => 'ucircumflex', 209 => 'Ntilde', 252 => 'udieresis', 210 => 'Ograve', 253 => 'yacute', 211 => 'Oacute', 254 => 'thorn', 212 => 'Ocircumflex', 255 => 'ydieresis', 213 => 'Otilde', }
- MARGIN_BOTTOM =
20
- MARGIN_IN =
40
- MARGIN_OUT =
30
- MARGIN_TOP =
20
- PAGE_NUMBER_SIZE =
8
- PAGE_NUMBER_YPOS =
10
- PAGE_TITLE_HEIGHT =
20
- VARIABLE_WIDTH_FONT =
"Helvetica"
- SYMBOL_FONT =
'Symbol'
- LANGUAGES =
{ :de => { :combinations => 'Kombinationen', :substance_index => 'Wirkstoffregister', }, :fr => { :combinations => 'Combinations', :substance_index => 'Registre de substances actives', }, }
Instance Method Summary collapse
- #_(key) ⇒ Object
- #add_substance_name(fachinfo) ⇒ Object
- #add_text_wrap(left, y, width, text, *args) ⇒ Object
- #anchor_name(num) ⇒ Object
- #chapter_format ⇒ Object
- #chapter_index_format ⇒ Object
- #combination_substances(tuples) ⇒ Object
- #company_name_format ⇒ Object
- #draw_background(color_map = COLOR_BG) ⇒ Object
- #draw_column_line ⇒ Object
- #draw_page_title(title) ⇒ Object
- #drug_name_format ⇒ Object
- #encrypted? ⇒ Boolean
- #fi_new_column ⇒ Object
- #fi_new_page ⇒ Object
- #flic_name_format ⇒ Object
- #generic_color(generic_type = :unknown, color_map = COLOR_BG) ⇒ Object
- #hyphenator=(hyphenator) ⇒ Object
-
#initialize(opts = {}) ⇒ FachinfoWriter
constructor
A new instance of FachinfoWriter.
- #initialize_formats ⇒ Object
- #kombi_index_format ⇒ Object
- #move_pointer(dy, *args) ⇒ Object
- #new_page(*args) ⇒ Object
- #page_type(num = @fi_page_number) ⇒ Object
- #page_type_standard ⇒ Object
- #page_type_substance_index ⇒ Object
- #page_type_substance_title ⇒ Object
- #paragraph_format ⇒ Object
- #preformatted_format ⇒ Object
- #prepare_substance_index ⇒ Object
- #section_format ⇒ Object
- #set_bg_bounds(xpos = nil, ypos = nil, width = nil, height = nil) ⇒ Object
- #set_flic_name(fachinfo_name) ⇒ Object
- #set_page_element_type(symbol) ⇒ Object
- #set_page_type_elements ⇒ Object
- #set_ptype_margins(ptype) ⇒ Object
- #single_substances(tuples) ⇒ Object
- #start_new_page(force = false) ⇒ Object
- #text_index_format ⇒ Object
- #wrap_tuple(tuple) ⇒ Object
- #write_alphabet ⇒ Object
- #write_chapter(chapter) ⇒ Object
- #write_company_name(name) ⇒ Object
- #write_drug_name(fachinfo_name) ⇒ Object
- #write_fachinfo(fachinfo) ⇒ Object
- #write_flic_name ⇒ Object
- #write_heading(chapter) ⇒ Object
- #write_index ⇒ Object
- #write_index_entry(substance, singles, combinations, first) ⇒ Object
- #write_last_minute ⇒ Object
- #write_outside_bound_text(ypos, size, txt, ptype) ⇒ Object
- #write_page_number(number = 1, ptype = nil) ⇒ Object
- #write_paragraph(paragraph) ⇒ Object
- #write_section(section) ⇒ Object
- #write_substance_index ⇒ Object
- #write_tuple(tuple, link_y = nil) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ FachinfoWriter
Returns a new instance of FachinfoWriter.
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 213 def initialize opts = {} @opts = {:color => true, :language => :de}.update(opts) super(:paper => 'A4', :orientation => :portrait) @black = Color::RGB.from_fraction(0, 0, 0) @white = Color::RGB.from_fraction(1, 1, 1) @color = Color::RGB.from_fraction(*COLOR_STD) @text_space_height = @page_height - MARGIN_TOP - MARGIN_BOTTOM @current_generic_type = :unknown @flic_name = "" @anchor = 0 @enforce_line_count = 0 @substance_index = SubstanceIndex.new # prepare basefonts (load them including differences) select_font(ALPHA_FONT, :differences => ISO_8859_1_DIFFERENCES) select_font(FIXED_WIDTH_FONT, :differences => ISO_8859_1_DIFFERENCES) select_font(SYMBOL_FONT, :differences => ISO_8859_1_DIFFERENCES) select_font(VARIABLE_WIDTH_FONT, :differences => ISO_8859_1_DIFFERENCES) initialize_formats end |
Instance Method Details
#_(key) ⇒ Object
236 237 238 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 236 def _ key LANGUAGES[@opts[:language]][key] end |
#add_substance_name(fachinfo) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 239 def add_substance_name(fachinfo) value = [ fachinfo.name, fachinfo.company_name, @fi_page_number, fachinfo.generic_type, fachinfo.substance_names.size, anchor_name(@anchor) ] fachinfo.substance_names.each { |substance| @substance_index.store(substance, value) } @substance_index end |
#add_text_wrap(left, y, width, text, *args) ⇒ Object
253 254 255 256 257 258 259 260 261 262 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 253 def add_text_wrap(left, y, width, text, *args) text.gsub!(/\302\255/u, '') rest = super(@left_margin, y, width, text, *args) @first_line_of_page = false @enforce_line_count += 1 if(@enforce_page_break == @enforce_line_count) start_new_page end rest end |
#anchor_name(num) ⇒ Object
263 264 265 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 263 def anchor_name(num) "anchor" + num.to_s end |
#chapter_format ⇒ Object
380 381 382 383 384 385 386 387 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 380 def chapter_format format = Format.new format.spacing_before = -5 format.spacing_after = -1 format.size = 7 format.font = VARIABLE_WIDTH_FONT format end |
#chapter_index_format ⇒ Object
421 422 423 424 425 426 427 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 421 def chapter_index_format format = Format.new format.spacing_before = -3 format.size = 7 format.font = VARIABLE_WIDTH_FONT format end |
#combination_substances(tuples) ⇒ Object
848 849 850 851 852 853 854 855 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 848 def combination_substances(tuples) tuples.select { |tuple| #max number of combination substances we want in #the index (tuple[4].to_i > 1) && (tuple[4].to_i < 6) }.compact end |
#company_name_format ⇒ Object
372 373 374 375 376 377 378 379 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 372 def company_name_format format = Format.new format.spacing_before = -1 format.size = 7 format.font = VARIABLE_WIDTH_FONT format.justification = :right format end |
#draw_background(color_map = COLOR_BG) ⇒ Object
266 267 268 269 270 271 272 273 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 266 def draw_background(color_map = COLOR_BG) return if @page_element_type == :page_type_substance_title color = generic_color(@current_generic_type, color_map) save_state fill_color color rectangle(*@bg_bounds).fill restore_state end |
#draw_column_line ⇒ Object
274 275 276 277 278 279 280 281 282 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 274 def draw_column_line save_state xpos = @left_margin - (@column_gap / 2) y2pos = @page_height - @margin_top_column stroke_style StrokeStyle.new(0.1, :cap => :round) stroke_color(Color::RGB.from_fraction(0, 0, 0)) line(xpos, MARGIN_BOTTOM, xpos, y2pos).stroke restore_state end |
#draw_page_title(title) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 283 def draw_page_title(title) save_state fill_color @black xpos = @left_margin ypos = @page_height - MARGIN_TOP - PAGE_TITLE_HEIGHT width = @page_width - MARGIN_IN - MARGIN_OUT rectangle(xpos, ypos, width, PAGE_TITLE_HEIGHT).fill restore_state fill_color @white y_text_pos = @page_height - PAGE_TITLE_HEIGHT - font_height(FONT_SIZE_TITLE) add_text(xpos, y_text_pos, title, FONT_SIZE_TITLE) fill_color @black @first_line_of_page = true end |
#drug_name_format ⇒ Object
364 365 366 367 368 369 370 371 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 364 def drug_name_format format = Format.new format.spacing_before = -8 format.size = 10 format.margin = 3 format.font = VARIABLE_WIDTH_FONT format end |
#encrypted? ⇒ Boolean
297 298 299 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 297 def encrypted? false end |
#fi_new_column ⇒ Object
320 321 322 323 324 325 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 320 def fi_new_column if(@opts[:color]) set_bg_bounds end @first_line_of_page = true end |
#fi_new_page ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 326 def fi_new_page @fi_page_number ||= 0 @fi_page_number += 1 unless(@page_element_type) set_page_element_type(:page_type_standard) end set_page_type_elements @current_width = column_width @first_line_of_page = true @blank_flic_name = true end |
#flic_name_format ⇒ Object
388 389 390 391 392 393 394 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 388 def flic_name_format format = Format.new format.ypos = 825 format.size = 10 format.font = VARIABLE_WIDTH_FONT format end |
#generic_color(generic_type = :unknown, color_map = COLOR_BG) ⇒ Object
337 338 339 340 341 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 337 def generic_color(generic_type=:unknown, color_map=COLOR_BG) Color::RGB.from_fraction(*(color_map[generic_type] \ || color_map[:unknown] \ || COLOR_BG[:unknown])) end |
#hyphenator=(hyphenator) ⇒ Object
342 343 344 345 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 342 def hyphenator=(hyphenator) @formats.each_value { |fmt| fmt.writer.hyphenator = hyphenator } @hyphenator = hyphenator end |
#initialize_formats ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 346 def initialize_formats @formats = {} @formats[:drug_name] = drug_name_format @formats[:company_name] = company_name_format @formats[:chapter] = chapter_format @formats[:flic_name] = flic_name_format @formats[:section] = section_format @formats[:paragraph] = paragraph_format @formats[:preformatted] = preformatted_format @formats[:chapter_index] = chapter_index_format @formats[:kombi_index] = kombi_index_format @formats[:text_index] = text_index_format @formats.each_value { |fmt| @fonts.each_key { |font| fmt.writer.select_font font, :differences => ISO_8859_1_DIFFERENCES } } end |
#kombi_index_format ⇒ Object
428 429 430 431 432 433 434 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 428 def kombi_index_format format = Format.new format.spacing_before = -1 format.size = 6 format.font = VARIABLE_WIDTH_FONT format end |
#move_pointer(dy, *args) ⇒ Object
315 316 317 318 319 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 315 def move_pointer(dy, *args) unless @first_line_of_page super -dy, *args end end |
#new_page(*args) ⇒ Object
443 444 445 446 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 443 def new_page(*args) write_last_minute super(*args) end |
#page_type(num = @fi_page_number) ⇒ Object
447 448 449 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 447 def page_type(num = @fi_page_number) ((num.to_i % 2) == 0) ? :even : :odd end |
#page_type_standard ⇒ Object
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 450 def page_type_standard @target_columns = COLUMNS_FI @column_gap = COLUMN_GAP_FI @write_alphabet = true @write_flic_name = true stop_columns() fill_color @color ptype = page_type set_ptype_margins(ptype) @y = @page_height - @top_margin @margin_top_column = MARGIN_TOP write_page_number(@fi_page_number, ptype) start_columns(@target_columns, @column_gap) if(@opts[:color]) set_bg_bounds end end |
#page_type_substance_index ⇒ Object
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 483 def page_type_substance_index stop_columns() fill_color @color ptype = page_type set_ptype_margins(ptype) @y = @page_height - @top_margin @margin_top_column = MARGIN_TOP @column_gap = COLUMN_GAP_INDEX @target_columns = COLUMNS_INDEX @write_alphabet = false @write_flic_name = false start_columns(@target_columns, @column_gap) write_flic_name if(@opts[:color]) set_bg_bounds end end |
#page_type_substance_title ⇒ Object
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 467 def page_type_substance_title stop_columns() fill_color @color ptype = page_type set_ptype_margins(ptype) @y = @page_height - @top_margin - 30 @margin_top_column = MARGIN_TOP + 30 @column_gap = COLUMN_GAP_INDEX @target_columns = COLUMNS_INDEX @write_alphabet = false @write_flic_name = false start_columns(@target_columns, @column_gap) if(@opts[:color]) set_bg_bounds end end |
#paragraph_format ⇒ Object
403 404 405 406 407 408 409 410 411 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 403 def paragraph_format format = Format.new format.spacing_before = -1 #format.spacing_after = -0.5 format.size = 7 format.font = VARIABLE_WIDTH_FONT format.justification = :full format end |
#preformatted_format ⇒ Object
412 413 414 415 416 417 418 419 420 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 412 def preformatted_format format = Format.new format.spacing_before = -3 format.spacing_after = -3 format.size = 5.3 format.font = FIXED_WIDTH_FONT format.justification = :left format end |
#prepare_substance_index ⇒ Object
767 768 769 770 771 772 773 774 775 776 777 778 779 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 767 def prepare_substance_index #prepend a new page #@pageset.unshift insert_mode(:on => true, :page => 0, :position => :before) set_page_element_type(:page_type_substance_title) start_new_page true #(true, @first_page, :before) set_page_type_elements @fi_page_number = 0 fi_new_page stop_columns select_font(VARIABLE_WIDTH_FONT) draw_page_title("<b> #{_(:substance_index).upcase} </b>") end |
#section_format ⇒ Object
395 396 397 398 399 400 401 402 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 395 def section_format format = Format.new format.spacing_before = -2.5 format.spacing_after = -1 format.size = 7 format.font = VARIABLE_WIDTH_FONT format end |
#set_bg_bounds(xpos = nil, ypos = nil, width = nil, height = nil) ⇒ Object
503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 503 def set_bg_bounds(xpos=nil, ypos=nil, width=nil, height=nil) @bg_bounds ||= [] xpos ||= @left_margin - (@column_gap / 2) ypos ||= @bottom_margin width ||= @page_width - @right_margin \ - xpos + (@column_gap / 2) height ||= @y - @bottom_margin @bg_bounds[0] = xpos @bg_bounds[1] = ypos @bg_bounds[2] = width @bg_bounds[3] = height end |
#set_flic_name(fachinfo_name) ⇒ Object
668 669 670 671 672 673 674 675 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 668 def set_flic_name(fachinfo_name) if(page_type == :odd) @flic_name = fachinfo_name elsif(@blank_flic_name) @flic_name = fachinfo_name @blank_flic_name = false end end |
#set_page_element_type(symbol) ⇒ Object
500 501 502 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 500 def set_page_element_type(symbol) @page_element_type = symbol end |
#set_page_type_elements ⇒ Object
526 527 528 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 526 def set_page_type_elements self.send(@page_element_type) end |
#set_ptype_margins(ptype) ⇒ Object
515 516 517 518 519 520 521 522 523 524 525 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 515 def set_ptype_margins(ptype) side_margins = [ MARGIN_IN, # left on odd pages MARGIN_OUT, # right on odd pages ] if(ptype == :even) side_margins.reverse! end left, right = side_margins margins_pt(MARGIN_TOP, left, MARGIN_BOTTOM, right) end |
#single_substances(tuples) ⇒ Object
856 857 858 859 860 861 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 856 def single_substances(tuples) tuples.select { |tuple| #only one substance in the single substance array tuple[4].to_i == 1 }.compact end |
#start_new_page(force = false) ⇒ Object
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 300 def start_new_page(force=false) draw_column_line if column_number > 1 num_pages = @pageset.size super if @pageset.size > num_pages fi_new_page else fi_new_column end if(@opts[:color]) #@bg_bounds[3] = @bottom_margin - @bg_bounds[1] set_bg_bounds draw_background end end |
#text_index_format ⇒ Object
435 436 437 438 439 440 441 442 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 435 def text_index_format format = Format.new format.spacing_before = -1 format.size = 5.5 format.justification = :left format.font = VARIABLE_WIDTH_FONT format end |
#wrap_tuple(tuple) ⇒ Object
862 863 864 865 866 867 868 869 870 871 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 862 def wrap_tuple(tuple) paragraph = ODDB::Text::Paragraph.new paragraph << tuple.at(0).to_s paragraph << " (" paragraph << tuple.at(2).to_s paragraph << ")\n" paragraph.set_format(:italic) paragraph << tuple.at(1) ParagraphWrapper.new(paragraph) end |
#write_alphabet ⇒ Object
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 538 def write_alphabet save_state letter = ODDB.search_term(@flic_name[0,1]).upcase # scope: define num outside of if-block num = 0 if(("A".."Z").include?(letter)) # 26 letters plus "*" for others # "A"[0] == 65 # num("A") == 27 # num("Z") == 1 # num("*") == 0 num = (26 + 65) - letter[0] else # "*" for others letter = "*" end height = @text_space_height / 27.0 ypos = MARGIN_BOTTOM + num * height width = MARGIN_OUT - ALPHA_GAP xpos = @page_width - width # select_layer(1) fill_color @black rectangle(xpos, ypos, width, height - ALPHA_GAP / 2).fill # select_layer(0) fill_color @white size = FONT_SIZE_ALPHA offset = (height - font_height(size) - \ font_descender(size)) / 2 xpos = @page_width - \ (text_width(letter, size) + width) / 2 previous = @current_font select_font(ALPHA_FONT) add_text(xpos, ypos + offset, letter, size) restore_state select_font(previous) end |
#write_chapter(chapter) ⇒ Object
574 575 576 577 578 579 580 581 582 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 574 def write_chapter(chapter) if(chapter.need_new_page?((@y - MARGIN_BOTTOM), @current_width, @formats)) start_new_page end write_heading(chapter) chapter.each_section { |section_wrapper| write_section(section_wrapper) } end |
#write_company_name(name) ⇒ Object
583 584 585 586 587 588 589 590 591 592 593 594 595 596 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 583 def write_company_name(name) format = @formats[:company_name] if(name.nil?) name = "" end move_pointer(format.spacing_before(name)) if(@opts[:color]) set_bg_bounds draw_background end text(name, :font_size => format.size, :justification => format.justification) move_pointer(format.spacing_after(name)) end |
#write_drug_name(fachinfo_name) ⇒ Object
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 597 def write_drug_name(fachinfo_name) format = @formats[:drug_name] add_destination(anchor_name(@anchor), "XYZ", @left_margin,@y,0) move_pointer(format.spacing_before(fachinfo_name)) height = format.get_height(fachinfo_name, @current_width) - format.margin set_bg_bounds(nil, @y - height, nil, height) map = (@opts[:color]) ? COLOR_DRUG_NAME_BG : GRAY_DRUG_NAME_BG draw_background(map) color = generic_color(@current_generic_type, COLOR_DRUG_NAME_FNT) fill_color color text(fachinfo_name, :font_size => format.size) move_pointer(-format.margin) name = CGI.escape(fachinfo_name[3..-1][/[^<®\ ]+/u]) url = "http://www.oddb.org/de/gcc/search/search_query/#{name}" add_link(url, @bg_bounds.at(0), @bg_bounds.at(1), @bg_bounds.at(0) + @bg_bounds.at(2), @bg_bounds.at(1) + @bg_bounds.at(3)) #set_bg_bounds(nil, @y) move_pointer(format.spacing_after(fachinfo_name)) fill_color @color end |
#write_fachinfo(fachinfo) ⇒ Object
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 631 def write_fachinfo(fachinfo) if(@fi_page_number.nil?) fi_new_page end puts fachinfo.name fachinfo_wrapper = FachinfoWrapper.new(fachinfo) if(fachinfo_wrapper.need_new_page?((@y - MARGIN_BOTTOM), @current_width, @formats)) start_new_page end @anchor += 1 add_substance_name(fachinfo) set_flic_name(fachinfo.name) @current_generic_type = fachinfo_wrapper.generic_type write_drug_name(fachinfo_wrapper.name) write_company_name(fachinfo_wrapper.company_name) fachinfo_wrapper.each_chapter { |chapter_wrapper| write_chapter(chapter_wrapper) } @bg_bounds[3] = @y - @bg_bounds.at(1) + @formats[:drug_name].spacing_before(fachinfo_wrapper.name) end |
#write_flic_name ⇒ Object
651 652 653 654 655 656 657 658 659 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 651 def write_flic_name format = @formats[:flic_name] save_state previous = @current_font select_font(format.font) write_outside_bound_text(format.ypos, format.size, @flic_name, page_type) restore_state select_font(previous) end |
#write_heading(chapter) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 619 def write_heading(chapter) format = @formats[:chapter] heading = chapter.heading if(heading != "") #save_state select_font(format.font) move_pointer(format.spacing_before(heading)) text("<b>" << chapter.heading << "</b>", :font_size => format.size) move_pointer(format.spacing_after(heading)) #restore_state end end |
#write_index ⇒ Object
788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 788 def write_index @substance_index.sort.each { |substance, tuples| singles = single_substances(tuples) combinations = combination_substances(tuples) first = unless(singles.empty?) singles.first else combinations.first end unless(first.nil?) write_index_entry(substance, singles,\ combinations, first) end } end |
#write_index_entry(substance, singles, combinations, first) ⇒ Object
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 803 def write_index_entry(substance, singles, combinations, first) format_chapter = @formats[:chapter_index] format_kombi = @formats[:kombi_index] format_text = @formats[:text_index] formats = { :paragraph => format_text, } bsubstance = "<b>" << substance << "</b>" para = wrap_tuple(first) height = @y - @bottom_margin \ - format_chapter.get_height(bsubstance, @current_width) - format_kombi.get_height("fo", @current_width) if(para.need_new_page?(height, @current_width, formats)) start_new_page end link_y = nil move_pointer(format_chapter.spacing_before(bsubstance)) if((singles.size \ + combinations.size) == 1) link_y = @y end text(bsubstance, :font_size => format_chapter.size, :justification => format_chapter.justification) move_pointer(format_chapter.spacing_after(bsubstance)) singles.each{ |tuple| write_tuple(tuple, link_y) link_y = nil } unless(combinations.empty?) para = wrap_tuple(combinations.first) fmt_str = "<i>#{_(:combinations)}</i>" height = @y - @bottom_margin \ - format_kombi.get_height(fmt_str, @current_width) if(para.need_new_page?(height, @current_width, formats)) start_new_page end move_pointer(format_kombi.spacing_before(fmt_str)) text(fmt_str, :font_size => format_kombi.size, :justification => format_kombi.justification) move_pointer(format_kombi.spacing_after(fmt_str)) combinations.each{ |tuple| write_tuple(tuple, link_y) link_y = nil } end end |
#write_last_minute ⇒ Object
660 661 662 663 664 665 666 667 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 660 def write_last_minute if(@write_flic_name == true) write_flic_name end if(page_type == :odd && @write_alphabet == true) write_alphabet end end |
#write_outside_bound_text(ypos, size, txt, ptype) ⇒ Object
676 677 678 679 680 681 682 683 684 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 676 def write_outside_bound_text(ypos, size, txt, ptype) xpos = if(ptype == :even) MARGIN_OUT else tw = text_width(txt, size) @page_width - MARGIN_OUT - tw end add_text(xpos, ypos, txt, size) end |
#write_page_number(number = 1, ptype = nil) ⇒ Object
685 686 687 688 689 690 691 692 693 694 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 685 def write_page_number(number = 1, ptype = nil) save_state ptype ||= page_type(number) previous = @current_font select_font(VARIABLE_WIDTH_FONT) write_outside_bound_text(PAGE_NUMBER_YPOS, PAGE_NUMBER_SIZE, number.to_s, ptype) restore_state select_font previous end |
#write_paragraph(paragraph) ⇒ Object
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 695 def write_paragraph(paragraph) format = if(paragraph.preformatted?) @formats[:preformatted] else @formats[:paragraph] end paragraph.hyphenator = @hyphenator available_height = @y - MARGIN_BOTTOM if(paragraph.need_new_page?(available_height, @current_width, @formats)) start_new_page available_height = @y - MARGIN_BOTTOM end unless(@first_line_of_page) available_height += format.spacing_before(paragraph.text) end column_height = @page_height - MARGIN_BOTTOM - MARGIN_TOP @enforce_line_count = 0 @enforce_page_break = paragraph.enforce_page_break?(available_height, @text_space_height, @current_width, format) #save_state previous_font = @current_base_font select_font(format.font) if paragraph.image? path = File.join(PROJECT_ROOT, 'doc', paragraph.src) if File.exist?(path) data = File.read(path) img, = Magick::Image.from_blob(data) do |info| info.size = size end size = "#{@current_width}x" data = img.to_blob do |info| info.depth = 8 end height = @current_width * img.rows / img.columns move_pointer(-height) move_pointer(format.spacing_before(paragraph.text)) add_image data, @left_margin, @y, @current_width end else move_pointer(format.spacing_before(paragraph.text)) text = paragraph.text paragraph.text.each_line { |line| if paragraph.preformatted? && /^-{53,}/u.match(line) line = line[0,52] end text(line.rstrip, :font_size => format.size, :justification => format.justification) } end #restore_state move_pointer(format.spacing_after(paragraph.text)) select_font(previous_font) end |
#write_section(section) ⇒ Object
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 750 def write_section(section) format = @formats[:section] if(section.need_new_page?(@y - MARGIN_BOTTOM, @current_width, @formats)) start_new_page end subheading = section.subheading if (paragraph = section.paragraphs.first) \ && paragraph.preformatted? && subheading[-1] != ?\n subheading += "\n" end move_pointer(format.spacing_before(subheading)) text(section.subheading, :font_size => format.size) move_pointer(format.spacing_after(subheading)) section.each_paragraph { |paragraph_wrapper| write_paragraph(paragraph_wrapper) } end |
#write_substance_index ⇒ Object
780 781 782 783 784 785 786 787 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 780 def write_substance_index prepare_substance_index set_page_element_type(:page_type_substance_index) @flic_name = _(:substance_index) start_columns(@target_columns, @column_gap) write_index draw_column_line if column_number > 1 end |
#write_tuple(tuple, link_y = nil) ⇒ Object
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 |
# File 'ext/fipdf/src/fachinfo_writer.rb', line 872 def write_tuple(tuple, link_y = nil) format = @formats[:text_index] generic_type = tuple.at(3) anchor = tuple.at(5) para = wrap_tuple(tuple) formats = { :paragraph => format, } height = @y - @bottom_margin # these two lines are important # the insert mode must be reset for every tuple # otherwise new pages won't be added to the page index # and will not display in the reader #@ez[:insertOptions][:id] = @first_page #@ez[:insertOptions][:pos] = :before if(para.need_new_page?(height, @current_width, formats)) start_new_page end if(link_y.nil?) link_y = @y end format = @formats[:text_index] color = generic_color(generic_type.intern, COLOR_DRUG_NAME_INDEX ) fill_color color text(para.text, :font_size => format.size, :justification => format.justification) =begin medic_name, company_name, page_number, generic_type, combination, anchor = tuple fill_color(generic_color(generic_type.intern, COLOR_DRUG_NAME_INDEX )) output_name = " " + medic_name.to_s + " ("+page_number.to_s + ")" output_company = "<i>"+" "+ company_name.to_s + "</i>" y_pos = (@bottom_margin \ + format.get_height(output_name, \ @current_width) \ + format.get_height(output_company, \ @current_width)) typographic_line_break_index(y_pos) ez_text(output_name, format.size, :justification => format.justification) ez_text(output_company, format.size, :justification => format.justification) =end add_internal_link(anchor.to_s, @left_margin \ , link_y, @left_margin + @current_width, @y \ + font_descender(format.size)) fill_color @color end |