Class: Emfsvg::Translation::Handlers::TextHandler

Inherits:
Object
  • Object
show all
Includes:
Emf::Emr::Binary::TypeCodes, SharedGdi
Defined in:
lib/emfsvg/translation/handlers/text_handler.rb

Overview

Translate to CreateFontIndirectW + SetTextColor + ExtTextOutW + DeleteObject.

v1 limitations:

* ASCII / BMP characters only (UTF-16LE encoding).
* No glyph-index path (ETO_GLYPH_INDEX).
* No Dx array (character spacing defaults to natural advance).
* LOGFONT built with default OutPrecision/ClipPrecision/Quality.

Constant Summary collapse

LOGFONT_SIZE =
92
EXTTEXTOUTW_FIXED_SIZE =
76

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedGdi

#clip_bounds_for, #emit_create_brush, #emit_create_pen, #emit_delete, #emit_restore_dc, #emit_save_dc, #with_gdi_state

Class Method Details

.call(element, context) ⇒ Object



23
24
25
# File 'lib/emfsvg/translation/handlers/text_handler.rb', line 23

def self.call(element, context)
  new.translate(element, context)
end

Instance Method Details

#translate(element, context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/emfsvg/translation/handlers/text_handler.rb', line 27

def translate(element, context)
  return if element.content.nil? || element.content.empty?

  clip_bounds = clip_bounds_for(element, context)
  wrap_with_clip = !clip_bounds.nil?
  transformed = element.transformed?

  emit_save_dc(context) if wrap_with_clip || transformed
  if transformed
    context.emit(Emf::Emr::Binary::Records::SetWorldTransform,
                 i_type: SETWORLDTRANSFORM,
                 xform: context.xform_wire_from(element.transform_matrix))
  end
  if wrap_with_clip
    context.emit(Emf::Emr::Binary::Records::IntersectClipRect,
                 i_type: INTERSECTCLIPRECT,
                 rcl_clip: context.rect_l(*clip_bounds))
  end
  font_handle = emit_create_font(element, context)
  emit_set_text_color(element, context)
  emit_ext_text_out_w(element, context)
  emit_delete(context, font_handle)
  emit_restore_dc(context) if wrap_with_clip || transformed
end