cupsffi 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cupsffi/lib.rb CHANGED
@@ -358,6 +358,24 @@ module CupsFFI
358
358
  :choices, :pointer
359
359
  end
360
360
 
361
+ class PPDAttrS < FFI::Struct
362
+ layout :name, [:char, PPD_MAX_NAME],
363
+ :spec, [:char, PPD_MAX_NAME],
364
+ :text, [:char, PPD_MAX_TEXT],
365
+ :value, :string
366
+ end
367
+
368
+ class PPDSizeS < FFI::Struct
369
+ layout :marked, :int,
370
+ :name, [:char, PPD_MAX_NAME],
371
+ :width, :float,
372
+ :length, :float,
373
+ :left, :float,
374
+ :bottom, :float,
375
+ :right, :float,
376
+ :top, :float
377
+ end
378
+
361
379
  # Parameters
362
380
  # - filename for PPD file
363
381
  # Returns
@@ -380,6 +398,28 @@ module CupsFFI
380
398
  # - pointer to PPDOptionS struct
381
399
  attach_function 'ppdNextOption', [:pointer], :pointer
382
400
 
401
+ # Parameters
402
+ # - pointer to PPDFileS struct
403
+ # - attribute name
404
+ # - spec name
405
+ # Returns
406
+ # - pointer to PPDAttrS struct
407
+ attach_function 'ppdFindAttr', [:pointer, :string, :string], :pointer
408
+
409
+ # Parameters
410
+ # - pointer to PPDFileS struct
411
+ # - attribute name
412
+ # - spec name
413
+ # Returns
414
+ # - pointer to PPDAttrS struct
415
+ attach_function 'ppdFindNextAttr', [:pointer, :string, :string], :pointer
416
+
417
+ # Parameters
418
+ # - pointer to PPDFileS struct
419
+ # - page name
420
+ # Returns
421
+ # - pointer to PPDSizeS struct
422
+ attach_function 'ppdPageSize', [:pointer, :string], :pointer
383
423
 
384
424
 
385
425
 
data/lib/cupsffi/ppd.rb CHANGED
@@ -63,4 +63,60 @@ class CupsPPD
63
63
  end
64
64
  options
65
65
  end
66
+
67
+ def attributes
68
+ attributes = []
69
+ attr_ptr = @ppd_file_s[:attrs].read_pointer
70
+ if !attr_ptr.null?
71
+ @ppd_file_s[:attrs].get_array_of_pointer(0, @ppd_file_s[:num_attrs]).each do |attr_ptr|
72
+ attribute = CupsFFI::PPDAttrS.new(attr_ptr)
73
+ attributes.push({
74
+ :name => String.new(attribute[:name]),
75
+ :spec => String.new(attribute[:spec]),
76
+ :text => String.new(attribute[:text]),
77
+ :value => String.new(attribute[:value]),
78
+ })
79
+ end
80
+ end
81
+ attributes
82
+ end
83
+
84
+ def attribute(name, spec=nil)
85
+ attributes = []
86
+ attribute_pointer = CupsFFI::ppdFindAttr(@pointer, name, spec)
87
+ while !attribute_pointer.null?
88
+ attribute = CupsFFI::PPDAttrS.new(attribute_pointer)
89
+ attributes.push({
90
+ :name => String.new(attribute[:name]),
91
+ :spec => String.new(attribute[:spec]),
92
+ :text => String.new(attribute[:text]),
93
+ :value => String.new(attribute[:value]),
94
+ })
95
+
96
+ attribute_pointer = CupsFFI::ppdFindNextAttr(@pointer, name, spec)
97
+ end
98
+ attributes
99
+ end
100
+
101
+ def page_size(name=nil)
102
+ size_ptr = CupsFFI::ppdPageSize(@pointer, name)
103
+ size = CupsFFI::PPDSizeS.new(size_ptr)
104
+ if size.null?
105
+ nil
106
+ else
107
+ {
108
+ :marked => (size[:marked] != 0),
109
+ :name => String.new(size[:name]),
110
+ :width => size[:width],
111
+ :length => size[:length],
112
+ :margin => {
113
+ :left => size[:left],
114
+ :bottom => size[:bottom],
115
+ :right => size[:right],
116
+ :top => size[:top]
117
+ }
118
+ }
119
+ end
120
+ end
121
+
66
122
  end
@@ -1,3 +1,3 @@
1
1
  module Cupsffi
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cupsffi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan Ehresman
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-10 00:00:00 -05:00
13
+ date: 2011-05-24 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency