tioga 1.17 → 1.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -21,9 +21,18 @@ right corners of the image. This allows the image to be rotated, streched, and
21
21
  it is placed -- or even reflected in either the horizontal or vertical by suitable choices
22
22
  for the corner locations.
23
23
 
24
- For a JPEG, you can simply give the filename for the image along with the location and the
25
- width and height. Sampled images can be monochrome, gray scale, RGB, or CMYK according to the value of the
26
- 'color_space' entry.
24
+ For a JPEG, you can simply give the filename for the image along with
25
+ the location and the width and height. Sampled images can be
26
+ monochrome, gray scale, RGB, or CMYK according to the value of the
27
+ 'color_space' entry. In most of the cases, it is actually unlikely
28
+ that you'll know the widths and heights of the images. For that, you
29
+ can use the #jpg_info function.
30
+
31
+ To display PNG images, use #load_png function that returns a
32
+ dictionnary suitable for use with #show_image. You just need to add
33
+ the coordinates to the dictionnary. Be warned that some PNG images,
34
+ such as the ones that use a fixed color palette, cannot be used for
35
+ the time being, and #load_png will raise an exception.
27
36
 
28
37
  The 'color_space' entry is set to 'MONO' or 'mono' for a monochrome image. The monochrome image is used as
29
38
  a 'stencil mask' for painting in the current fill color. The default is to paint places corresponding
@@ -55,7 +64,7 @@ are stored as three bytes, corresponding to red, green, and blue intensities
55
64
  If the 'color_space' entry is 'HLS' or 'hls', then samples
56
65
  are stored as three bytes, corresponding to hue, lightness, and saturation
57
66
  (the hue angle in the range 0.0 to 360.0 is stored as round(hue*256/360)).
58
- [Note: internally, the hls data is copied and converted to rgb -- see string_hls_to_rgb.]
67
+ *Note* internally, the hls data is copied and converted to rgb -- see string_hls_to_rgb.
59
68
 
60
69
  In 4-color printing, as in ink-jet printers, images are painted using cyan, magenta, yellow, and black inks.
61
70
  The corresponding 'color_space' is 'CMYK' or 'cmyk'. For this case, samples are stored as four bytes,
@@ -87,6 +96,13 @@ default in Tioga; setting the 'interpolate' entry
87
96
  in the image dictionary to +false+ should disable it
88
97
  (but note that some PDF viewer implementations seem to ignore this flag).
89
98
 
99
+ Defining figures for later use: when calling #show_image, it returns an
100
+ internal reference to the image. If you need to display this image again
101
+ (with different values of the coordinates), you can skip the whole image
102
+ definition again, and pass the returned value as the 'ref' key in the image
103
+ dictionnary. In that case, you still need the 'll', 'lr', 'ul' keys of the
104
+ image display.
105
+
90
106
  Dictionary Entries
91
107
  'll' => [x, y] # location for the lower-left corner of the image
92
108
  'lr' => [x, y] # location for the lower-right corner of the image
@@ -95,6 +111,7 @@ Dictionary Entries
95
111
  'w' # alias for 'width'
96
112
  'height' => an_integer # number of rows of samples in the image
97
113
  'h' # alias for 'height'
114
+ 'ref' => a_value # a value previously returned by #show_image or #register_image, to reuse and already defined image
98
115
  'jpg' => a_string # file containing the JPEG image
99
116
  'jpeg', 'JPEG', 'JPG' # aliases for 'jpg'
100
117
  'color_space' => string_or_colormap # tells how to interpret the image data
@@ -226,6 +243,49 @@ link:images/Sampled_Data.png
226
243
  def show_image(dict)
227
244
  end
228
245
 
246
+
247
+
248
+ =begin rdoc
249
+
250
+ Registers an image for later use. This function does not actually
251
+ display anythig, but the return value can be passed an arbitrary
252
+ number of times as the 'ref' key of the argument to #show_image. The
253
+ values understood for dict are the same as for #show_image, excepted
254
+ that the coordinates are not used.
255
+
256
+ You can even embed images you don't display.
257
+
258
+ =end
259
+
260
+ def register_image(dict)
261
+ end
262
+
263
+ =begin rdoc
264
+
265
+ Loads a PNG image from a png file. It returns a dictionnary that can
266
+ be passed directly to #register_image, or to #show_image (but in the
267
+ latter case, you need to add the coordinates, of course).
268
+
269
+ This function will fail on some types of PNG images for some
270
+ colorspaces (in particular for indexed images).
271
+
272
+ The alpha channel is transformed into a grayscale mask.
273
+
274
+ =end
275
+
276
+ def load_png(file)
277
+ end
278
+
279
+ =begin rdoc
280
+
281
+ Returns some information about the given JPEG file, and in particular
282
+ its width and height.
283
+ =end
284
+
285
+ def jpg_info(file)
286
+ end
287
+
288
+
229
289
  =begin rdoc
230
290
  Creates a data representation suitable for use with show_image from the values in the Dtable _data_
231
291
  according to the entries in the dictionary _dict_. Only _data_ rows between 'first_row' and
@@ -843,6 +843,51 @@ EOT
843
843
  assert_equal(cols, cols2)
844
844
  end
845
845
 
846
+ def test_ffr_2
847
+ text = ""
848
+ 6.times do |i|
849
+ text << "#{i}\t#{i*0.5}\tmy_#{i}\t#{i**2}\tThis is the line number #{i}\n"
850
+ end
851
+
852
+ stream = StringIO.new(text)
853
+ cols = Dvector.fancy_read(stream)
854
+ assert_equal(cols.size, 10)
855
+ 6.times do |i|
856
+ assert_equal(cols[0][i], i.to_f)
857
+ assert_equal(cols[1][i], i.to_f*0.5)
858
+ assert(cols[2][i].nan?)
859
+ assert_equal(cols[3][i], i.to_f**2)
860
+ assert_equal(cols[9][i], i)
861
+ end
862
+
863
+ # Next try, slurping all lines
864
+ stream = StringIO.new(text)
865
+ cols = Dvector.fancy_read(stream, nil, { 'last_col' => 4})
866
+ assert_equal(cols.size, 6)
867
+ 6.times do |i|
868
+ assert_equal(cols[0][i], i.to_f)
869
+ assert_equal(cols[1][i], i.to_f*0.5)
870
+ assert(cols[2][i].nan?)
871
+ assert_equal(cols[3][i], i.to_f**2)
872
+ assert(cols[4][i].nan?)
873
+ assert_equal(cols[5][i], "is the line number #{i}")
874
+ end
875
+
876
+ stream = StringIO.new(text)
877
+ cols = Dvector.fancy_read(stream, nil, {
878
+ 'last_col' => 3,
879
+ 'text_columns' => [0, 2]
880
+ })
881
+ assert_equal(cols.size, 5)
882
+ 6.times do |i|
883
+ assert_equal(cols[0][i], i.to_s)
884
+ assert_equal(cols[1][i], i.to_f*0.5)
885
+ assert_equal(cols[2][i], "my_#{i}")
886
+ assert_equal(cols[3][i], i.to_f**2)
887
+ assert_equal(cols[4][i], "This is the line number #{i}")
888
+ end
889
+ end
890
+
846
891
  def test_compute_formula
847
892
  v = Dvector[1,2,3]
848
893
  w = Dvector[3,2,1]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tioga
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.17'
4
+ version: '1.18'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2013-08-31 00:00:00.000000000 Z
17
+ date: 2014-03-13 00:00:00.000000000 Z
18
18
  dependencies: []
19
19
  description: ! 'Tioga is a blend of PDF, pdfTex and ruby into a library to make
20
20