win32-clipboard 0.6.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9de821de27a89d47b900c8107d9414bf1b55f12e
4
- data.tar.gz: 5b8a1bff4c1dc00adfed808e4ebe95d796972f40
3
+ metadata.gz: f1e9d66dee40bab2644c326883aa740d9cda4c7a
4
+ data.tar.gz: a35a610cd2d18dd40fdc04486b9492c41df6a065
5
5
  SHA512:
6
- metadata.gz: 3bee364da37395f10308a3ae1e46091dd07a4f67009df7a4ea44e13fc67ccdb3063fe2507866e09a37e54cec0ba712f6cc81dc39c96c1345e8f5ded358bc4701
7
- data.tar.gz: f863bf39bdd43f8efa720affae4c2a80e30eb268badf6f288938c1c28bf842f4bbe19722c66bb88271c98d01eb9c55615f4adb769b03d6b1b9dec71cbf93a52c
6
+ metadata.gz: 019a82dd2e1110b082fa59c815f551b53a1620db009112d5d506889c88527f78d8cd84692112627ebb1f725406cd258a60d22c07552377922e68a8502c845c19
7
+ data.tar.gz: 22c2fad73246cd26eedca03248e5a3f0afc2d28bea15350341807ee4c57102f5c9089ae175a1cf47e016886df1f3c473afa197200796d0164b6d6e3afdfd5fa3
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 0.6.2 - 27-Jan-2014
2
+ * Fix and more tests for the internal get_image_data. Thanks go to u338steven
3
+ for the spot and patches.
4
+
1
5
  == 0.6.1 - 20-Jan-2014
2
6
  * Use 32-bit versions of GetWindowLong and SetWindowLong functions on 32-bit
3
7
  versions of Ruby. Thanks go to Orgad Shaneh for the spot.
data/Rakefile CHANGED
@@ -45,6 +45,12 @@ namespace :test do
45
45
  t.verbose = true
46
46
  t.test_files = FileList['test/test_clipboard.rb']
47
47
  end
48
+
49
+ Rake::TestTask.new(:image) do |t|
50
+ t.warning = true
51
+ t.verbose = true
52
+ t.test_files = FileList['test/test_image_clipboard.rb']
53
+ end
48
54
  end
49
55
 
50
56
  task :default => 'test:all'
@@ -16,7 +16,7 @@ module Win32
16
16
  extend Windows::Structs
17
17
 
18
18
  # The version of this library
19
- VERSION = '0.6.1'
19
+ VERSION = '0.6.2'
20
20
 
21
21
  # Clipboard formats
22
22
 
@@ -162,7 +162,7 @@ module Win32
162
162
  buf = clip_data
163
163
  extra = 4
164
164
  when BITMAP, DIB
165
- buf = clip_data[14..clip_data.length] # sizeof(BITMAPFILEHEADER) = 14
165
+ buf = clip_data[BITMAP_FILE_HEADER_SIZE..clip_data.length]
166
166
  extra = 0
167
167
  end
168
168
 
@@ -320,6 +320,14 @@ module Win32
320
320
 
321
321
  private
322
322
 
323
+ # sizeof(BITMAPFILEHEADER)
324
+
325
+ BITMAP_FILE_HEADER_SIZE = 14
326
+
327
+ # sizeof(BITMAPINFOHEADER)
328
+
329
+ BITMAP_INFO_HEADER_SIZE = 40
330
+
323
331
  # Opens the clipboard and prevents other applications from modifying
324
332
  # the clipboard content until it is closed.
325
333
  #
@@ -357,8 +365,7 @@ module Win32
357
365
 
358
366
  bmi = BITMAPINFO.new(ptr)
359
367
 
360
- size_image = bmi[:bmiHeader][:biSizeImage]
361
- size_image = buf_size + 16 if size_image == 0
368
+ file_size = buf_size + BITMAP_FILE_HEADER_SIZE
362
369
 
363
370
  # Calculate the header size
364
371
  case bmi[:bmiHeader][:biBitCount]
@@ -369,10 +376,14 @@ module Win32
369
376
  when 8
370
377
  table_size = 256
371
378
  when 16, 32
372
- if bmi[:bmiHeader][:biCompression] == 0
379
+ if bmi[:bmiHeader][:biCompression] == BI_RGB
380
+ table_size = bmi[:bmiHeader][:biClrUsed]
381
+ elsif bmi[:bmiHeader][:biCompression] == BI_BITFIELDS
373
382
  table_size = bmi[:bmiHeader][:biClrUsed]
374
- elsif compression == 3
375
- table_size = 3
383
+ if bmi[:bmiHeader][:biSize] == BITMAP_INFO_HEADER_SIZE
384
+ # Add bit fields size
385
+ table_size += 3
386
+ end
376
387
  else
377
388
  raise "invalid bit/compression combination"
378
389
  end
@@ -382,10 +393,12 @@ module Win32
382
393
  raise "invalid bit count"
383
394
  end # case
384
395
 
385
- # TODO: Document what's happening here.
386
- offset = 0x36 + (table_size * 4)
396
+ # offset = sizeof(BITMAPFILEHEADER)
397
+ # + sizeof(BITMAPINFOHEADER or BITMAPV4HEADER or BITMAPV5HEADER)
398
+ # + (color table size)
399
+ offset = BITMAP_FILE_HEADER_SIZE + bmi[:bmiHeader][:biSize] + (table_size * 4)
387
400
 
388
- buf = "\x42\x4D" + [size_image].pack('L') + 0.chr * 4 + [offset].pack('L') + ptr.read_bytes(buf_size)
401
+ buf = "\x42\x4D" + [file_size].pack('L') + 0.chr * 4 + [offset].pack('L') + ptr.read_bytes(buf_size)
389
402
  ensure
390
403
  GlobalUnlock(handle) if handle
391
404
  end
@@ -6,5 +6,7 @@ module Windows
6
6
  GWL_USERDATA = -21
7
7
  GWL_WNDPROC = -4
8
8
  CF_TEXT = 1
9
+ BI_RGB = 0
10
+ BI_BITFIELDS = 3
9
11
  end
10
12
  end
Binary file
Binary file
Binary file
Binary file
data/test/img/1bit.bmp ADDED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/test/img/4bit.bmp ADDED
Binary file
data/test/img/8bit.bmp ADDED
Binary file
@@ -14,7 +14,7 @@ include Win32
14
14
 
15
15
  class TC_Win32_ClipBoard < Test::Unit::TestCase
16
16
  test "version is set to expected value" do
17
- assert_equal('0.6.1', Clipboard::VERSION)
17
+ assert_equal('0.6.2', Clipboard::VERSION)
18
18
  end
19
19
 
20
20
  test "data method basic functionality" do
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ ###########################################################################
3
+ # test_image_clipboard.rb
4
+ #
5
+ # Test suite for the win32-clipboard library(only get_image_data).
6
+ ###########################################################################
7
+ require 'test-unit'
8
+ require 'win32/clipboard'
9
+ include Win32
10
+
11
+ class TC_Image_ClipBoard < Test::Unit::TestCase
12
+ class << self
13
+ def startup
14
+ $is_ready = false
15
+ @t = Thread.new do
16
+ begin
17
+ Win32::Clipboard.notify_change {$is_ready = true}
18
+ rescue => e
19
+ puts $!
20
+ puts e.backtrace
21
+ end
22
+ end
23
+ # wait for notify_change running
24
+ until $is_ready
25
+ Clipboard.set_data('foo')
26
+ sleep 0.1
27
+ end
28
+ end
29
+
30
+ def shutdown
31
+ @t.kill
32
+ end
33
+ end
34
+
35
+ dir = File.join(File.dirname(__FILE__), 'img')
36
+ Dir.glob("#{dir}/*.bmp") do |file|
37
+ test "get_image_data file: " + File.basename(file) do
38
+ $is_ready = false
39
+
40
+ bmp = File.open(file, "rb").read
41
+ Clipboard.set_data(bmp, Clipboard::DIB)
42
+
43
+ until $is_ready
44
+ sleep 0.1
45
+ end
46
+
47
+ assert_equal(Clipboard.data(Clipboard::DIB), bmp)
48
+ end
49
+ end
50
+
51
+ end
@@ -2,7 +2,7 @@ require "rubygems"
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'win32-clipboard'
5
- spec.version = '0.6.1'
5
+ spec.version = '0.6.2'
6
6
  spec.authors = ['Daniel J. Berger', 'Park Heesob']
7
7
  spec.license = 'Artistic 2.0'
8
8
  spec.email = 'djberg96@gmail.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: win32-clipboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-20 00:00:00.000000000 Z
12
+ date: 2014-01-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -75,8 +75,21 @@ files:
75
75
  - lib/win32/windows/constants.rb
76
76
  - lib/win32/windows/functions.rb
77
77
  - lib/win32/windows/structs.rb
78
+ - test/img/16bit.bmp
79
+ - test/img/16bit_bitfields.bmp
80
+ - test/img/16bit_bitfields1.bmp
81
+ - test/img/16bit_bitfields2.bmp
82
+ - test/img/1bit.bmp
83
+ - test/img/24bit.bmp
84
+ - test/img/32bit.bmp
85
+ - test/img/32bit_bitfields.bmp
86
+ - test/img/32bit_bitfields1.bmp
87
+ - test/img/32bit_bitfields2.bmp
88
+ - test/img/4bit.bmp
89
+ - test/img/8bit.bmp
78
90
  - test/test_clipboard.rb
79
91
  - test/test_html_clipboard.rb
92
+ - test/test_image_clipboard.rb
80
93
  - win32-clipboard.gemspec
81
94
  homepage: http://github.com/djberg96/win32-clipboard
82
95
  licenses: