Skip to content

Commit

Permalink
Mostly fix compile warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlWright committed Apr 2, 2011
1 parent b9f669b commit f4b9742
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 165 deletions.
19 changes: 9 additions & 10 deletions src/eg_afm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ exists(File) ->
false
end.

first([X]) ->
first([_]) ->
[];
first([H|T]) ->
[H|first(T)].
Expand All @@ -196,7 +196,7 @@ mk_eg_font_map(FontMap) ->
All = lists:map(fun(I) -> element(2, I) end, FontMap),
Str = ["-module(eg_font_map).\n",
"-export([handler/1,all_fonts/0]).\n",
lists:map(fun({Mod,Font,I}) ->
lists:map(fun({Mod, Font, _I}) ->
["handler(\"",Font,"\")-> ", Mod,";\n"]
end, FontMap),
"handler(_) -> undefined.\n",
Expand All @@ -223,7 +223,6 @@ parse(F,Index) ->
{First,Last,Widths} = normalise_widths(Cw1),
%% io:format("First=~p last=~p ~n",[First,Last]),
Kern1 = lists:map(fun({XY,_,W}) -> {XY, W} end, Kern),
Ascender = get_val(L, "Ascender"),
T = #afm2{baseFont=Fn, widths=Widths, firstChar=First,
lastChar=Last, kernPairs=Kern1,
ascender=get_val(L, "Ascender"),
Expand Down Expand Up @@ -289,7 +288,7 @@ mk_kern([{{I,J},K}|T]) ->
mk_kern([]) ->
["kern(_,_) -> 0.\n"].

widths_2_erl(N, []) ->
widths_2_erl(_N, []) ->
["width(_)->unknown.\n"];
widths_2_erl(N, [0|T]) ->
widths_2_erl(N+1, T);
Expand All @@ -300,15 +299,15 @@ widths_2_erl(N, [H|T]) ->

normalise_widths(Pairs) ->
P1 = lists:sort(Pairs),
{First,Width} = hd(P1),
{First, _Width} = hd(P1),
{Last, Ws} = gather(First, P1, []),
{First,Last, Ws}.

gather(X, [{X,W}], L) ->
{X, lists:reverse([W|L])};
gather(X, [{X,W}|T], L) ->
gather(X+1, T, [W|L]);
gather(X, Z=[{Y,W}|T], L) when Y > X ->
gather(X, Z = [{Y, _W} | _T], L) when Y > X ->
gather(X+1,Z,[0|L]).

get_fixed_pitch(L) ->
Expand Down Expand Up @@ -394,7 +393,7 @@ parse_kerning({_,Str="KPX " ++ _}, Cw) ->
io:format("UUgh:~s:~p~n",[Str,Other]),
no
end;
parse_kerning(_, Cw) ->
parse_kerning(_, _Cw) ->
no.

charno(C, Cw) ->
Expand All @@ -412,7 +411,7 @@ get_char_widths(L, Enc) ->
end,
lists:foldl(F, [], L).

add_char({Line,Str= "C " ++ _}, Acc, Enc) ->
add_char({_Line, Str= "C " ++ _}, Acc, Enc) ->
case parse_char_data(Str, Enc) of
{-1,_,_} ->
Acc;
Expand All @@ -430,7 +429,7 @@ parse_char_data(S, "FontSpecific") ->
Other ->
io:format("wot is:~s:~pn",[S, Other])
end;
parse_char_data(S, Enc) ->
parse_char_data(S, _Enc) ->
case string:tokens(S, "\s\r\n") of
["C",_,";","WX",W,";","N",Name,";"|_] ->
C = name_to_char(Name),
Expand Down Expand Up @@ -589,7 +588,7 @@ str2lines([H|T], Line, C, L) ->
$\n -> str2lines(T, Line+1,[],[{Line,lists:reverse([$\n|C])}|L]);
_ -> str2lines(T, Line, [H|C], L)
end;
str2lines([], Line, [], L) ->
str2lines([], _Line, [], L) ->
lists:reverse(L);
str2lines([], Line, C, L) ->
lists:reverse([{Line,lists:reverse(C)}|L]).
Expand Down
12 changes: 6 additions & 6 deletions src/eg_embed.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ embed(F) ->
O = lists:map(fun({_,_,B}) -> B end, P),
file:write_file(F ++ ".synth", O).

%% Parse_pfb -> [{Type,Len,Bin}]
%% Parse_pfb -> [{Type, Len, Bin}]
%% The lengths are the required lengths in the
%% object descriptor ...

parse_pfb(F) ->
{ok, Bin} = file:read_file(F),
L = parse(Bin).
parse(Bin).

parse(<<128,3>>) ->
[];
parse(B) ->
{B1,B2} = split_binary(B, 6),
[128,Type,N1,N2,N3,N4] = binary_to_list(B1),
{B1, B2} = split_binary(B, 6),
[128, Type, N1, N2, N3, N4] = binary_to_list(B1),
Len = N1 + N2*256 + N3*256*256 + N4*256*256*256,
%% io:format("Chunk: ~p length=~p~n",[Type, Len]),
case Len of
0 -> [];
_ ->
{B3,B4} = split_binary(B2, Len),
[{Type,Len,B3}|parse(B4)]
{B3, B4} = split_binary(B2, Len),
[{Type, Len, B3}|parse(B4)]
end.


Expand Down
21 changes: 13 additions & 8 deletions src/eg_font_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@

-include("../include/eg.hrl").

-export([start/0, stop/0, char_width/2, data/1, info/1, kern/2]).
-export([start/0,
stop/0,
char_width/2,
data/1,
info/1,
kern/2]).

%% ============================================================================

Expand All @@ -36,7 +41,7 @@ start() ->
true ->
true;
false ->
fonts = ets:new(fonts, [named_table,set,public]),
fonts = ets:new(fonts, [named_table, set, public]),
true
end.

Expand Down Expand Up @@ -75,7 +80,7 @@ info(Index) ->
[{_,I}] ->
I;
[] ->
exit({font_server_info,Index})
exit({font_server_info, Index})
end.

data(Fontname) ->
Expand All @@ -87,18 +92,18 @@ data(Fontname) ->
end.

char_width(N, Char) ->
case ets:lookup(fonts, {width,N,Char}) of
[{_,W}] ->
case ets:lookup(fonts, {width, N, Char}) of
[{_, W}] ->
W;
[] ->
io:format("Cannot figure out width of:~p ~p~n",[N, Char]),
io:format("Cannot figure out width of:~p ~p~n", [N, Char]),
io:format("Possible \n in code etc~n"),
1000
end.

kern(N, KP) ->
case ets:lookup(fonts, {kern,N,KP}) of
[{_,W}] ->
case ets:lookup(fonts, {kern, N, KP}) of
[{_, W}] ->
W;
[] ->
0
Expand Down
6 changes: 3 additions & 3 deletions src/eg_hyphenate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ remove_singleton1([$-,H]) -> [H];
remove_singleton1([H|T]) -> [H|remove_singleton1(T)];
remove_singleton1([]) -> [].

make_word([{Pos,C}|T], Pos, L) ->
make_word([{Pos, _C}|T], Pos, L) ->
[$-|make_word(T, Pos, L)];
make_word(S=[{Pos,_}|_], Pos1, [H|T]) when Pos1 < Pos ->
[H|make_word(S, Pos1+1, T)];
Expand All @@ -210,11 +210,11 @@ merge([{Pos,C}|T], L) -> merge(T, merge1(Pos, C, L)).

merge1(Pos, C, []) -> [{Pos,C}];
merge1(Pos, C, [{Pos,C1}|T]) when C > C1 -> [{Pos,C}|T];
merge1(Pos, C, [{Pos,C1}|T]) -> [{Pos,C1}|T];
merge1(Pos, _C, [{Pos,C1}|T]) -> [{Pos,C1}|T];
merge1(Pos, C, [H|T]) -> [H|merge1(Pos, C, T)].

keep_odd(L) ->
lists:filter(fun({Pos,Count}) -> odd(Count) end, L).
lists:filter(fun({Count}) -> odd(Count) end, L).

odd(X) ->
(X rem 2) == 1.
Expand Down
15 changes: 10 additions & 5 deletions src/eg_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ find_files(Dir, Re, Flag) ->

find_files(Dir, Reg, Recursive, Fun, Acc) ->
case file:list_dir(Dir) of
{ok, Files} -> find_files(Files, Dir, Reg, Recursive, Fun, Acc);
{error, _} -> Acc
{ok, Files} ->
find_files(Files, Dir, Reg, Recursive, Fun, Acc);
{error, _} ->
Acc
end.

find_files([File|T], Dir, Reg, Recursive, Fun, Acc0) ->
Expand Down Expand Up @@ -77,9 +79,12 @@ file_type(File) ->
case file:read_file_info(File) of
{ok, Facts} ->
case Facts#file_info.type of
regular -> regular;
directory -> directory;
_ -> error
regular ->
regular;
directory ->
directory;
_ ->
error
end;
_ ->
error
Expand Down
26 changes: 13 additions & 13 deletions src/eg_line_break.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ first_break_line(All=[H|T], Sum, Len, L, SplitType) ->
{{Sum, Len, lists:reverse(remove_leading_spaces(L))},
remove_leading_spaces(All)}
end;
first_break_line([], Sum, Len, L, SplitType) ->
first_break_line([], Sum, Len, L, _SplitType) ->
{{Sum, Len, lists:reverse(remove_leading_spaces(L))}, []}.


Expand Down Expand Up @@ -262,9 +262,9 @@ safe_width(Val) ->

%% return: integer() >= 1, number of initial Str letters to use
%% split even if a single letter is > Len (doesn't fit in Len)
force_split(Str, StrLen, Len, GLen, Font, PointSize) when GLen =< 0 ->
force_split(_Str, _StrLen, _Len, GLen, _Font, _PointSize) when GLen =< 0 ->
1;
force_split(Str, StrLen, Len, GLen, Font, PointSize) when GLen >= StrLen ->
force_split(_Str, StrLen, _Len, GLen, _Font, _PointSize) when GLen >= StrLen ->
StrLen;
force_split(Str, StrLen, Len, GLen, Font, PointSize) ->
case fits(Str, Len, GLen, Font, PointSize) of
Expand All @@ -290,9 +290,9 @@ fits(Str, Len, GLen, Font, PointSize) ->

%% return: integer() >= 1, number of initial Str letters to use
%% split even if a single letter (+ hyphen) is > Len (doesn't fit in Len)
hyphen_split(Str, StrLen, Len, GLen, Font, PointSize) when GLen =< 0 ->
hyphen_split(_Str, _StrLen, _Len, GLen, _Font, _PointSize) when GLen =< 0 ->
1;
hyphen_split(Str, StrLen, Len, GLen, Font, PointSize) when GLen >= StrLen ->
hyphen_split(_Str, StrLen, _Len, GLen, _Font, _PointSize) when GLen >= StrLen ->
StrLen;
hyphen_split(Str, StrLen, Len, GLen, Font, PointSize) ->
case fits(Str ++ "-", Len, GLen, Font, PointSize) of
Expand Down Expand Up @@ -375,14 +375,14 @@ collect_line([], L) ->
justify(Text, Widths, Rules) ->
%% dbg_io("justify Text=~p widths=~p~n",[Text,Widths]),
case iterate([{0,Text,Widths,[],Rules}], none, 20) of
{Cost, Lines, Widths1, Spill, Rules} ->
{_Cost, Lines, Widths1, Spill, Rules} ->
Lines1 = lists:map(fun(I) -> {richText, I} end, Lines),
{Lines1, Widths1, {richText, Spill}};
none ->
impossible
end.

iterate([], Best, Max) ->
iterate([], Best, _Max) ->
Best;
iterate(L, Best, Max) ->
L1 = next_generation(L),
Expand Down Expand Up @@ -435,9 +435,9 @@ finalise([H|T], Best, L) ->
finalise([], Best, L) ->
{Best, L}.

trim(0, L) -> [];
trim(N, [H|T]) -> [H|trim(N-1, T)];
trim(N, []) -> [].
trim(0, _L) -> [];
trim(N, [H | T]) -> [H | trim(N-1, T)];
trim(_N, []) -> [].

%% ----------------------------------------------------------------------------

Expand Down Expand Up @@ -507,7 +507,7 @@ worse_break_line(All=[H|T], Len, L) ->
false ->
worse_break_line(T, Len, [H|L])
end;
worse_break_line([], Len, L) ->
worse_break_line([], _Len, L) ->
{lists:reverse(L), []}.

filter_candidates(Partitions, Len, Q) ->
Expand Down Expand Up @@ -575,7 +575,7 @@ filter_candidates(Partitions, Len, Q) ->
%% 1) Before does not begin with a space
%% 2) After does begin with a space

break_before([], After, Len, Q, L, _) ->
break_before([], After, _Len, _Q, _L, _) ->
check_after_invarient(After),
L;
break_before(Before, After, Len, Q, L0, Rules) ->
Expand Down Expand Up @@ -661,7 +661,7 @@ make_partitions([H|T], Rules, Before, Final) ->
false ->
make_partitions(T, Rules, [H|Before], Final)
end;
make_partitions([], Rules, _, Final) ->
make_partitions([], _Rules, _, Final) ->
Final.

%% extract segment x y S a b c -> {[x,y], [S,a,b,c]}
Expand Down
2 changes: 1 addition & 1 deletion src/eg_mk_hyphen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ split([], HyphenRules) -> {lists:reverse(HyphenRules), []};
%% hyphen rules and rule exceptions found
split(["\\hyphenation" | ExcpL], HyphenRules) -> {lists:reverse(HyphenRules),
ExcpL};
split(["\\" ++ _ | ExcpL], _) -> throw(unkown_dic_syntax);
split(["\\" ++ _ | _ExcpL], _) -> throw(unkown_dic_syntax);
split([HyphenRule | R], HyphenRules) -> split(R, [HyphenRule | HyphenRules]).


Expand Down
Loading

0 comments on commit f4b9742

Please sign in to comment.