Permalink
Browse files

All the type of PNG now work in NGerlguten.

I'm still working on why images don't look the same in Foxit and Acrobat, but I've just
got to keep grinding. This time I just could see the difference between Smask and SMask.
It matters in a PDF, but my brain just didn't see the difference.

PS: They look best in Foxit right now.
  • Loading branch information...
1 parent 21417eb commit 597ab607880587c5df71df2c8fd83c5c32735c37 @CarlWright committed Jun 12, 2010
View
@@ -113,7 +113,7 @@ mk_image(I, File, #image{alias=_Alias, width=W, height=H}) ->
Extras = [{"Filter", {name,"FlateDecode"}},
{"BitsPerComponent", Data_precision},
{"ColorSpace",{name, pngcolor(Ncomponents)}},
- {"Smask", {ptr, J, 0}}],
+ {"SMask", {ptr, J, 0}}],
ExtraObj = {{obj,J, 0}, {stream,
@@ -129,19 +129,20 @@ mk_image(I, File, #image{alias=_Alias, width=W, height=H}) ->
6 ->
J = I + 1,
Extras = [{"Filter", {name,"FlateDecode"}},
- {"BitsPerComponent", Data_precision},
{"ColorSpace",{name, pngcolor(Ncomponents)}},
- {"Smask", {ptr, J, 0}}],
+ {"SMask", {ptr, J, 0}},
+ {"BitsPerComponent", Data_precision}
+ ],
ExtraObj = {{obj,J, 0}, {stream,
{dict,[{"Type",{name,"XObject"}},
{"Subtype",{name,"Image"}},
{"Width",Width},
{"Height", Height},
- {"BitsPerComponent", Data_precision},
- {"Filter", {name,"FlateDecode"}},
{"ColorSpace",{name, "DeviceGray"}},
+ {"Filter", {name,"FlateDecode"}},
+ {"BitsPerComponent", Data_precision},
{"Decode",{array,[0,1]}}]},
Alpha_channel}}
end;
@@ -320,7 +321,6 @@ process_png( <<_Length:32, $I:8, $H:8, $D:8, $R:8,
process_png( <<Length:32, $P:8, $L:8, $T:8, $E:8, Data:Length/binary-unit:8, _CRC:32, Rest/binary >>,
Params, MoreParams, Palette, Image, Alpha_channel) ->
- io:format("Palette length = ~w~n",[Length]),
process_png( Rest, Params, MoreParams, << Palette/bits, Data/bits>>, Image, Alpha_channel);
process_png( <<Length:32, $I:8, $D:8, $A:8, $T:8, Data:Length/binary-unit:8, _CRC:32, Rest/binary >>,
@@ -399,18 +399,11 @@ extractAlphaAndData({png_head,{Width, Height, Color_type, Data_precision}},Image
%% separate the image and alpha channel data streams
{NewImage,AlphaChannel} = breakoutLines({pngbits(Color_type)* Data_precision, Data_precision}, NoFilterImage),
- io:format("channel separated~n"),
- ok = file:write_file("image.bin",[NewImage]),
- ok = file:write_file("alpha.bin",[AlphaChannel]),
+
%% compress the two streams and return them
- {ok,A} = deflate_stream(NewImage),
+ {ok,A} = deflate_stream(NewImage),
{ok,B} = deflate_stream(AlphaChannel),
-
- <<C:64/binary,_/binary>> = AlphaChannel,
- io:format("Alpha bytes = ~w~n",[C]),
- <<D:64/binary,_/binary>> = NewImage,
- io:format("Image bytes = ~w~n",[D]),
{A,B}.
@@ -467,7 +460,6 @@ breakoutLines(Sizes,ScanLines) ->
%% @doc filters gone, now we separate the image and alpha data
breakout(Sizes, << >>,Pixels, Alpha_channel) ->
- io:format("Stream size = ~w and ~w~n",[bit_size(Pixels), bit_size(Alpha_channel)]),
{Pixels, Alpha_channel};
breakout({PixelSize, AlphaSize}, Stream, Pixels, Alpha_channel) ->
<<Pixel:PixelSize/bits, Alpha:AlphaSize/bits, Rest/bitstring>> = Stream,
View
Binary file not shown.
View
@@ -34,13 +34,19 @@ test()->
PDF = eg_pdf:new(),
eg_pdf:set_pagesize(PDF,a4),
eg_pdf:set_page(PDF,1),
-
-
-
-
+ eg_pdf:set_font(PDF, "Victorias-Secret", 14),
eg_pdf_lib:moveAndShow(PDF, 350, 185, "Type 4"),
+
+ eg_pdf:save_state(PDF),
+ eg_pdf:set_fill_color(PDF,red),
+ eg_pdf:rectangle(PDF, 350,200,16,16, fill),
+ eg_pdf:restore_state(PDF),
+
+ eg_pdf:save_state(PDF),
+ eg_pdf:set_fill_color(PDF,red),
+ eg_pdf:rectangle(PDF, 340,480,56,56, fill),
eg_pdf:image(PDF,"../test/images/page_white_text.png", {350,500},{height,16}),
-
+ eg_pdf:restore_state(PDF),
{Serialised, _PageNo} = eg_pdf:export(PDF),
file:write_file("../test/eg_test11.pdf",[Serialised]),
View
Binary file not shown.
View
@@ -0,0 +1,51 @@
+%%==========================================================================
+%% Copyright (C) 2010 Carl Wright
+%%
+%% Permission is hereby granted, free of charge, to any person obtaining a
+%% copy of this software and associated documentation files (the
+%% "Software"), to deal in the Software without restriction, including
+%% without limitation the rights to use, copy, modify, merge, publish,
+%% distribute, sublicense, and/or sell copies of the Software, and to permit
+%% persons to whom the Software is furnished to do so, subject to the
+%% following conditions:
+%%
+%% The above copyright notice and this permission notice shall be included
+%% in all copies or substantial portions of the Software.
+%%
+%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+%% OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+%% MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+%% NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+%% DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+%% OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+%% USE OR OTHER DEALINGS IN THE SOFTWARE.
+%%
+%% Authors: Carl Wright <wright@servicelevel.net>
+%% Purpose: PNG image testing
+%%==========================================================================
+
+-module(eg_test12).
+
+-export([test/0]).
+
+%% ============================================================================
+
+test()->
+ PDF = eg_pdf:new(),
+ eg_pdf:set_pagesize(PDF,a4),
+ eg_pdf:set_page(PDF,1),
+
+ eg_pdf:set_font(PDF, "Victorias-Secret", 14),
+ eg_pdf_lib:moveAndShow(PDF, 50, 20, "Type 6"),
+
+
+ eg_pdf:save_state(PDF),
+ eg_pdf:set_fill_color(PDF,gainsboro),
+ eg_pdf:rectangle(PDF, 50,35,240,320, fill),
+ eg_pdf:image(PDF,"../test/images/dice.png",{50,35}, {240,320}),
+ eg_pdf:restore_state(PDF),
+
+ {Serialised, _PageNo} = eg_pdf:export(PDF),
+ file:write_file("../test/eg_test12.pdf",[Serialised]),
+ eg_pdf:delete(PDF).
+
View
Binary file not shown.

0 comments on commit 597ab60

Please sign in to comment.