Class: WirisPlugin::ImageFormatControllerPng

Inherits:
Object
  • Object
show all
Extended by:
ImageFormatControllerInterface
Includes:
Wiris
Defined in:
lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb

Instance Method Summary collapse

Methods included from ImageFormatControllerInterface

ImageFormatController

Constructor Details

#initializeImageFormatControllerPng



9
10
11
# File 'lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb', line 9

def initialize()
  super()
end

Instance Method Details

#getContentTypeObject



12
13
14
# File 'lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb', line 12

def getContentType()
  return "image/png"
end

#getMetrics(bytes, ref_output) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/com/wiris/plugin/impl/ImageFormatControllerPng.rb', line 15

def getMetrics(bytes,ref_output)
  output = ref_output
  width = 0
  height = 0
  dpi = 0
  baseline = 0
  bi = BytesInput.new(bytes)
  n = bytes::length()
  alloc = 10
  b = Bytes::alloc(alloc)
  bi::readBytes(b,0,8)
  n-= 8
  while n>0
    len = bi::readInt32()
    typ = bi::readInt32()
    if typ==1229472850
      width = bi::readInt32()
      height = bi::readInt32()
      bi::readInt32()
      bi::readByte()
    else 
      if typ==1650545477
        baseline = bi::readInt32()
      else 
        if typ==1883789683
          dpi = bi::readInt32()
          dpi = (Math::round(dpi/39.37))
          bi::readInt32()
          bi::readByte()
        else 
          if len>alloc
            alloc = len
            b = Bytes::alloc(alloc)
          end
          bi::readBytes(b,0,len)
        end
      end
    end
    bi::readInt32()
    n-= len+12
  end
  if output!=nil
    PropertiesTools::setProperty(output,"width",""+width.to_s)
    PropertiesTools::setProperty(output,"height",""+height.to_s)
    PropertiesTools::setProperty(output,"baseline",""+baseline.to_s)
    if dpi!=96
      PropertiesTools::setProperty(output,"dpi",""+dpi.to_s)
    end
    r = ""
  else 
    r = (((("&cw="+width.to_s)+"&ch=")+height.to_s)+"&cb=")+baseline.to_s
    if dpi!=96
      r = (r+"&dpi=")+dpi.to_s
    end
  end
  return r
end