Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Worried out a problem with eg_block.erl postioning...

Added Emakefile to build all the erl files... still need a regular Makefile to run some of the programs initially when you first install. They make erl files that are part of the complete system.
  • Loading branch information...
commit 684a24fbdf92258f70060ce627b3f5f43b2c1bbf 1 parent 31b3ee2
@CarlWright authored
View
18 include/eg.hrl
@@ -26,7 +26,7 @@
template, % current template (Module Name)
page, % current page
dict, % dictionary with keys{free,Page,Box}
- % {initialsed, Page, Template}
+ % {initialsed, Page, Template}
tagMap % current TagMap (function of the box)
}).
@@ -45,7 +45,7 @@
xHeight}). % num
-record(info, {creator,creationDate, producer, author, title, subject,
- keywords}).
+ keywords}). % fields in the header of a PDF
-record(pdfContext, {
info,
@@ -60,7 +60,9 @@
}).
--record(image,{alias,width,height}).
+-record(image,{ alias,
+ width,
+ height}).
-record(box,{name=default, %name of the box
x=10, % X coordinate of top left hand corner of box
@@ -73,6 +75,7 @@
grid=false, % plot a grid
continue=false,
fontSize=12, % default font for box
+ justify=justified, % text justification scheme (justified, centered, right_justified, left_justified)
bg=default % background color in box= default | {R,G,B}
}).
@@ -91,10 +94,15 @@
}).
--record(face, {font, pointSize, vOffset, color, breakable}).
+-record(face, {font,
+ pointSize,
+ vOffset,
+ color,
+ breakable}).
+% This is used to pass font choices for different tags into eg_table
-record(table,
- { def_font="Times-Bold", % Default font choice
+ { def_font="Times-Roman", % Default font choice
em_font="Times-Bold", % font for <em> tag
b_font="Times-Bold", % font for <b> tag
code_font="Courier-Bold"}). % font for <code> tag
View
3  src/Emakefile
@@ -0,0 +1,3 @@
+{'./*',[{i, "../include"}, {outdir, "../ebin"}, debug_info, strict_record_tests]}.
+{'../test/template testing/*',[{i, "../include"}, {outdir, "../ebin"}, debug_info, strict_record_tests]}.
+{'../test/*',[{i, "../include"}, {outdir, "../ebin"}, debug_info, strict_record_tests]}.
View
99 src/eg.hrl
@@ -1,99 +0,0 @@
-%%==========================================================================
-%% Copyright (C) 2003 Joe Armstrong
-%%
-%% 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.
-%%==========================================================================
-
--record(env, { pdf, % PDF process
- currentBox, % name of currentBox
- template, % current template (Mopdule Name)
- page, % current page
- dict, % dictionary with keys{free,Page,Box}
- % {initialsed, Page, Template}
- tagMap % current TagMap (function of the box)
- }).
-
--record(afm2, {baseFont, % FontName
- firstChar, % first char in widths table
- lastChar, % last char in Widths table
- widths, % the widths table (0=undefined)
- kernPairs, % [{{C1,C2},K}]
- ascender, % num
- capHeight, % num
- descender, % num
- flags, % num
- fontBBox, % {int,int,int,int}
- italicAngle, % num
- stemV, % num
- xHeight}). % num
-
--record(info, {creator,creationDate, producer, author, title, subject,
- keywords}). % fields in the header of a PDF
-
--record(pdfContext, {
- info,
- fonts,
- font_handler,
- images=[],
- currentpage,
- pages=[],
- scripts=[],
- mediabox,
- procset={undefined,undefined} %% { imageb,imagec }
- }).
-
-
--record(image,{ alias,
- width,
- height}).
-
--record(box,{x=10, % X coordinate of top left hand corner of box
- y=800, % Y coordinate of top left hand corner of box
- width=210, % Width in points (72 point=1 inch)
- leading=12, % leading in points
- lines=1, % # lines in box
- next=none, % next= none | {DeltaPage, Tag}
- free=1, % first free line in the box
- grid=false, % plot a grid
- bg=default % background color in box= default | {R,G,B}
- }).
-
--record(tagMap, {name=default, % Tag name
- font="Times-Roman", % Font name
- color=default, % default | {R,G,B}
- size=11, % font size
- voff=0, % vertical offset
- break=true % can do line breaks in blanks
- }).
-
-
--record(face, {font,
- pointSize,
- vOffset,
- color,
- breakable}).
-
-% This is used to pass font choices for different tags into eg_table
-%
--record(table,
- { def_font="Times-Roman", % Default font choice
- em_font="Times-Bold", % font for <em> tag
- b_font="Times-Bold", % font for <b> tag
- code_font="Courier-Bold"}). % font for <code> tag
View
37 src/eg_block.erl
@@ -27,13 +27,13 @@
-module (eg_block).
--export([block/11, block/10]).
+-export([block/11, block/10, colored_inner_block/11, inner_block/10]).
-include("../include/eg.hrl").
%%
-%% @doc block() processes one or more paragraphs correctly
+%% @doc block() processes one or more paragraphs correctly into PDF content
%%
%% parameters to control its output
%%
@@ -41,7 +41,7 @@
%%
%% Color = the color of the box that the block of text is in
%%
-%% Sample = the content to format as a block of text
+%% Sample = the content to format as a block of text i.e. "<p> a para with <em> big </em> thoughts </p>"
%%
%% X = the X coordinate of the top left corner of the block of text
%%
@@ -76,22 +76,35 @@
%% </pre>
+%% @doc process an XML block of content into a block of PDf text with a color background
block(PDF, Color, Sample, X, Y, Measure, PtSize, Leading, NLines, Justification, TagMap) ->
Width = Measure + 20,
- Ht = NLines * PtSize + 20,
+ Ht = (NLines * Leading) + 20,
box(PDF, Color, X, Y-Ht+10, Width, Ht),
- block(PDF, Sample, X+10, Y+10, Measure, PtSize, Leading, NLines, Justification, TagMap).
-
+ block(PDF, Sample, X+10, Y , Measure, PtSize, Leading, NLines, Justification, TagMap).
+
+%% @doc process a parsed XML block of content into a block of PDf text with a color background
+
+colored_inner_block(PDF, Color, Sample, X, Y, Measure, PtSize, Leading, NLines, Justification, TagMap) ->
+ Width = Measure + 20,
+ Ht = (NLines * Leading) + 20,
+ box(PDF, Color, X, Y-Ht+10, Width, Ht),
+ inner_block(PDF, Sample, X+10, Y-10, Measure, PtSize, Leading, NLines, Justification, TagMap).
+
+%% @doc process an XML block of content into a block of PDf text with a blank background
+
block(PDF, Sample, X, Y, Measure, PtSize, Leading, NLines, Justification, TagMap) ->
- block1(PDF, eg_xml_lite:parse_all_forms(Sample),X, Y, Measure, PtSize, Leading, NLines, Justification, TagMap).
+ inner_block(PDF, eg_xml_lite:parse_all_forms(Sample),X, Y, Measure, PtSize, Leading, NLines, Justification, TagMap).
+
+%% @doc process a parsed XML block of content into a block of PDf text with a blank background
-block1(PDF, [{xml, Xml}], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap) ->
+inner_block(PDF, [{xml, Xml}], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap) ->
block2(PDF, [{xml, Xml}], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap),
ok;
-block1(PDF, [{xml, Xml} | T], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap) ->
- Height =block2(PDF, [{xml, Xml}], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap),
- block1(PDF, T, X, Y - Height, Len, PtSize, Leading, NLines, Justification, TagMap).
+inner_block(PDF, [{xml, Xml} | T], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap) ->
+ Height = block2(PDF, [{xml, Xml}], X, Y, Len, PtSize, Leading, NLines, Justification, TagMap),
+ inner_block(PDF, T, X, Y - Height, Len, PtSize, Leading, NLines, Justification, TagMap).
block2(PDF, [{xml, Xml}], X, Y, Len, _PtSize, Leading, NLines, Justification, TagMap) ->
@@ -105,7 +118,7 @@ block2(PDF, [{xml, Xml}], X, Y, Len, _PtSize, Leading, NLines, Justification, Ta
impossible ->
io:format("Cannot break line are widths ok~n");
{Lines,_,_} ->
- Code = eg_richText2pdf:richText2pdf(PDF, X, Y, justified, 0, Lines,
+ Code = eg_richText2pdf:richText2pdf(PDF, X, Y, Justification, 0, Lines,
Leading, Widths, Off),
eg_pdf:begin_text(PDF),
eg_pdf:append_stream(PDF, Code),
View
4 src/eg_pdf.erl
@@ -371,8 +371,12 @@ ellipse(PID, {X, Y}, {RX, RY})->
append_stream(PID, eg_pdf_op:ellipse({X, Y}, {RX, RY})).
+%% @doc Stroke a rectangle area.
%% If Stroke Type is not appended in arguments, explicit
%% stroke command "path(StrokeType)" has to be executed.
+%%
+%% X, Y designate the lower left corner of the rectangle.
+
rectangle(PID,{X,Y},{WX,WY}) ->
rectangle(PID,X,Y,WX,WY).
View
26 src/erlguten.erl
@@ -37,35 +37,11 @@
test() -> format("../test/template testing/test1.map").
bug() -> format("../test/template testing/test2.map").
-
+
batch([X]) ->
format(atom_to_list(X)).
-%% A map file has the following structure
-%% <data page="1">
-%% <template name="template1">
-%% <intro>
-%% <p>...</p>
-%% <q>...</q>
-%% </intro>
-%% <body>
-%% ...
-%% </body>
-%% </template>
-%%
-%% Logic:
-%% in Env
-%% set template=template1
-%% set current page=1
-%% enter intro
-%% set currentBox = intro
-%% set dict entry {initialised, Page, one}
-%% set dict entry {free, Page, intro} = 1
-%% set tagMap for template1:tagMap(one, intro)
-%% call template1:handler(p, Args, Data, Env) -> Env1
-%% call template2:handler(q, Args, Data, Env1) -> Env2
-%% etc.
format(File) ->
V = eg_xml_lite:parse_file(File),
View
2  test/eg_test3.erl
@@ -21,7 +21,7 @@
%% USE OR OTHER DEALINGS IN THE SOFTWARE.
%%
%% Author: Joe Armstrong <joe@sics.se>
-%% Purpose: Test cases
+%% Purpose: Test cases
%%==========================================================================
-module(eg_test3).
View
BIN  test/eg_test3.pdf
Binary file not shown
View
21 test/template testing/template1.erl
@@ -182,19 +182,16 @@ tag_map(Env, Template, Box, Object) ->
end
end, [],Dict).
-handler(Box, ParaTag, Args, Data, Env) ->
+handler(Box, TagMap, Args, Data, Env) ->
[{raw, InText}] = Data,
- Text = eg_richText:str2richText(InText),
- writeBlock(Env#env.pdf,Text,0,Box#box.x, Box#box.y,
- Box#box.fontSize, Box#box.leading, 0, Box#box.width),
+ case Box#box.bg of
+ default -> eg_block:block(Env#env.pdf, InText,
+ Box#box.x, Box#box.y, Box#box.width, Box#box.fontSize,
+ Box#box.leading, Box#box.lines, Box#box.justify, TagMap);
+ _ -> eg_block:block(Env#env.pdf, Box#box.bg, InText,
+ Box#box.x, Box#box.y, Box#box.width, Box#box.fontSize,
+ Box#box.leading, Box#box.lines, Box#box.justify, TagMap)
+ end,
Env.
-writeBlock(PDF, Text, Rot, X, Y, PointSize, Leading, Offset, Width) ->
- Widths = [Width-Offset|lists:duplicate(30,Width)],
- Off = [Offset|lists:duplicate(30,0)],
- {Lines,_,_} = eg_line_break:break_richText(Text,{justified, Widths}),
- Code = eg_richText2pdf:richText2pdf(PDF, X, Y, justified, Rot, Lines,
- Leading, Widths, Off),
- io:format("Code=~p~n",[Code]),
- eg_pdf:append_stream(PDF, Code).
Please sign in to comment.
Something went wrong with that request. Please try again.