Class: CTioga2::TextSizeWatcher
- Inherits:
-
Object
- Object
- CTioga2::TextSizeWatcher
- Defined in:
- lib/ctioga2/utils.rb
Overview
This class watches over a list of named texts and can be queried for size/position information.
Instance Attribute Summary collapse
-
#bb ⇒ Object
A left, bottom, right, up bounding box (in output coordinates divided by 10).
-
#watched_names ⇒ Object
Watched text names.
Instance Method Summary collapse
- #compute_bb(t) ⇒ Object
-
#initialize ⇒ TextSizeWatcher
constructor
A new instance of TextSizeWatcher.
-
#update_margins(t, margins, padding = 2, min = 4) ⇒ Object
Given the MarginsBox with which the text was drawn, returns another MarginsBox item that specifies how much the text extends from the previous box.
- #watch(*names) ⇒ Object
Constructor Details
#initialize ⇒ TextSizeWatcher
Returns a new instance of TextSizeWatcher.
438 439 440 |
# File 'lib/ctioga2/utils.rb', line 438 def initialize @watched_names = Set.new end |
Instance Attribute Details
#bb ⇒ Object
A left, bottom, right, up bounding box (in output coordinates divided by 10)
436 437 438 |
# File 'lib/ctioga2/utils.rb', line 436 def bb @bb end |
#watched_names ⇒ Object
Watched text names
432 433 434 |
# File 'lib/ctioga2/utils.rb', line 432 def watched_names @watched_names end |
Instance Method Details
#compute_bb(t) ⇒ Object
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 |
# File 'lib/ctioga2/utils.rb', line 482 def compute_bb(t) @bb = nil for w in @watched_names info = t.get_text_size(w) if info.key? 'points' # We need to take every single point, since for rotated # text, potentially all coordinates are different for p in info['points'] update_bb(*p) end end end end |
#update_margins(t, margins, padding = 2, min = 4) ⇒ Object
Given the MarginsBox with which the text was drawn, returns another MarginsBox item that specifies how much the text extends from the previous box. Works using the current frame coordinates.
Padding in big points
Min is the minimum size, also in big points.
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 |
# File 'lib/ctioga2/utils.rb', line 454 def update_margins(t, margins, padding = 2, min = 4) compute_bb(t) if ! @bb # Don't change anything if the bounding box does not exist return margins end left, top, right, bottom = *margins.to_frame_coordinates(t) xl = 0.1 * t.convert_page_to_output_x(t.convert_frame_to_page_x(left)) xr = 0.1 * t.convert_page_to_output_x(t.convert_frame_to_page_x(right)) yt = 0.1 * t.convert_page_to_output_y(t.convert_frame_to_page_y(top)) yb = 0.1 * t.convert_page_to_output_y(t.convert_frame_to_page_y(bottom)) vals = [ xl - @bb[0], @bb[2] - xr, @bb[3] - yt, yb - @bb[1]].map do |x| x += padding x = if x > min x else min end Graphics::Types::Dimension.new(:bp, x) end return Graphics::Types::MarginsBox. new(*vals) end |
#watch(*names) ⇒ Object
442 443 444 |
# File 'lib/ctioga2/utils.rb', line 442 def watch(*names) @watched_names += names end |