pdfshaver 0.0.1.alpha → 0.0.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a34c73145fff7cd843f8770b4cdb14648b0d8e8
4
- data.tar.gz: 543a70e710dc09646580d1bb0fff7bce6f41fe5e
3
+ metadata.gz: 47c0de381cc44eaea49ef37b21928598d0c905cf
4
+ data.tar.gz: 08cdd9fb20961c659c24667652c1fe07dc4c29bc
5
5
  SHA512:
6
- metadata.gz: 3bca072b82f7710883dec16c6be56fcd696ef074c40b55ca1139f3671985ea7690fad1f2e7cfb0333f4ec480d1b92b2c722e3fa990a1e7a8b19f6b2bbc814ac0
7
- data.tar.gz: 3ec48a4b055c0b985567f5922194dbd853a489e392f64cf5ee9b641dd3e45ce9641b2028b4b93d6d802c10516b8cfb4e37575e73c29d27d6a831c31f0a551bf1
6
+ metadata.gz: 85f7c759a3ebd29a922db660626872f207579bd4706e2e1c4b14eee71d9b550ebca5e17d579ce30850f201ba63a418da0f3171850f0d6291a54af176f6a72801
7
+ data.tar.gz: 1c72fd8441a91e4b4245ec1e55894b4fd7693ac4b58a60d2178e00f8560ef952bcefcd2c5c562f1e8dcaf24be9d1c18a4740d3bd78c8828a28969a959b0d3dd4
@@ -35,12 +35,15 @@ bool Page::render(char* path, int width, int height) {
35
35
 
36
36
  // Create bitmap. width, height, alpha 1=enabled,0=disabled
37
37
  bool alpha = false;
38
+ printf("just about to allocate bitmap w:%d, h:%d\n", width, height);
38
39
  FPDF_BITMAP bitmap = FPDFBitmap_Create(width, height, alpha);
39
- if (!bitmap) { return false; }
40
+ printf("BITMAP CREATED\n");
41
+ if (!bitmap) { printf("ALLOCATING BITMAP FAILED"); return false; }
40
42
 
43
+ printf("FILLING BITMAP");
41
44
  // fill all pixels with white for the background color
42
45
  FPDFBitmap_FillRect(bitmap, 0, 0, width, height, 0xFFFFFFFF);
43
-
46
+ printf("BITMAP FILLED");
44
47
  // Render a page to a bitmap in RGBA format
45
48
  // args are: *buffer, page, start_x, start_y, size_x, size_y, rotation, and flags
46
49
  // flags are:
@@ -53,7 +56,7 @@ bool Page::render(char* path, int width, int height) {
53
56
  int rotation = 0;
54
57
  int flags = FPDF_PRINTING; // A flag defined in PDFium's codebase.
55
58
  FPDF_RenderPageBitmap(bitmap, this->fpdf_page, start_x, start_y, width, height, rotation, flags);
56
-
59
+ printf("RENDERED BITMAP");
57
60
  // The stride holds the width of one row in bytes. It may not be an exact
58
61
  // multiple of the pixel width because the data may be packed to always end on a byte boundary
59
62
  int stride = FPDFBitmap_GetStride(bitmap);
@@ -66,6 +69,7 @@ bool Page::render(char* path, int width, int height) {
66
69
  ((stride * height) > (INT_MAX / 3))
67
70
  );
68
71
  if (bitmapIsntValid){
72
+ printf("BITMAP ISN'T VALID");
69
73
  FPDFBitmap_Destroy(bitmap);
70
74
  return false;
71
75
  }
@@ -79,16 +83,20 @@ bool Page::render(char* path, int width, int height) {
79
83
  FIBITMAP *raw = FreeImage_ConvertFromRawBits(
80
84
  (BYTE*)FPDFBitmap_GetBuffer(bitmap), width, height, stride, bpp, red_mask, green_mask, blue_mask, topdown);
81
85
 
86
+ printf("ALLOCATED MAP");
82
87
  // at this point we're done with the FPDF bitmap and can destroy it.
83
88
  FPDFBitmap_Destroy(bitmap);
84
-
89
+ printf("FREE BITMAP");
85
90
  // Conversion to jpg or gif require that the bpp be set to 24
86
91
  // since we're not exporting using alpha transparency above in FPDFBitmap_Create
87
92
  FIBITMAP *image = FreeImage_ConvertTo24Bits(raw);
93
+ printf("CONVERT TO 24BITS2");
88
94
  FreeImage_Unload(raw);
95
+ printf("DEALLOCATE RAW");
89
96
 
90
97
  // figure out the desired format from the file extension
91
98
  FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename(path);
99
+ printf("DEDUCE FORMAT");
92
100
 
93
101
  bool success = false;
94
102
  if ( FIF_GIF == format ){
@@ -100,10 +108,11 @@ bool Page::render(char* path, int width, int height) {
100
108
  // All other formats should be just a save call
101
109
  success = FreeImage_Save(format, image, path, 0);
102
110
  }
111
+ printf("SAVED IMAGE");
103
112
 
104
113
  // unload the image
105
114
  FreeImage_Unload(image);
106
-
115
+ printf("UNLOADED IMAGE");
107
116
  return success;
108
117
  }
109
118
 
@@ -26,6 +26,8 @@ module PDFShaver
26
26
 
27
27
  def extract_dimensions_from_gm_geometry_string(arg)
28
28
  dimensions = {}
29
+ return dimensions if arg.nil? or arg.empty?
30
+ raise ArgumentError, "argument is not a String" unless arg.kind_of? String
29
31
  arg.match(GM_MATCHER) do |match|
30
32
 
31
33
  # grab parsed tokens
@@ -4,7 +4,7 @@ require 'pdfshaver/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'pdfshaver'
7
- s.version = PDFShaver::VERSION + ".alpha"
7
+ s.version = PDFShaver::VERSION + ".alpha1"
8
8
  s.licenses = ['MIT']
9
9
  s.summary = "Shave pages off of PDFs as images"
10
10
  s.authors = ["Ted Han", "Nathan Stitt"]
@@ -62,6 +62,11 @@ describe "Resize arguments" do
62
62
  end
63
63
  end
64
64
 
65
+ it "should return an empty hash with nil or an empty string" do
66
+ @page.extract_dimensions_from_gm_geometry_string(nil).must_equal({})
67
+ @page.extract_dimensions_from_gm_geometry_string("").must_equal({})
68
+ end
69
+
65
70
  it "should specify width and height" do
66
71
  w = @page.width.to_i
67
72
  h = @page.height.to_i
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfshaver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 0.0.1.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ted Han