pdfshaver 0.0.1.alpha → 0.0.1.alpha1
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 +4 -4
- data/ext/pdfium_ruby/page.cpp +14 -5
- data/lib/pdfshaver/page.rb +2 -0
- data/pdfshaver.gemspec +1 -1
- data/test/gm_compatability_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47c0de381cc44eaea49ef37b21928598d0c905cf
|
4
|
+
data.tar.gz: 08cdd9fb20961c659c24667652c1fe07dc4c29bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85f7c759a3ebd29a922db660626872f207579bd4706e2e1c4b14eee71d9b550ebca5e17d579ce30850f201ba63a418da0f3171850f0d6291a54af176f6a72801
|
7
|
+
data.tar.gz: 1c72fd8441a91e4b4245ec1e55894b4fd7693ac4b58a60d2178e00f8560ef952bcefcd2c5c562f1e8dcaf24be9d1c18a4740d3bd78c8828a28969a959b0d3dd4
|
data/ext/pdfium_ruby/page.cpp
CHANGED
@@ -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
|
-
|
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
|
|
data/lib/pdfshaver/page.rb
CHANGED
@@ -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
|
data/pdfshaver.gemspec
CHANGED
@@ -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 + ".
|
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
|