Permalink
Browse files

changed to load fonts info when the webserver is started.

  • Loading branch information...
1 parent a7f012c commit 6c1df09a2d722d509e5bb4cf6768da28a8f951ee huiqing committed Sep 14, 2012
Showing with 15 additions and 17 deletions.
  1. +1 −7 src/egd_font.erl
  2. +1 −1 src/egd_render.erl
  3. +3 −0 src/percept2.erl
  4. +10 −9 src/percept2_image.erl
View
@@ -23,7 +23,7 @@
-module(egd_font).
-export([load/1, size/1, glyph/2]).
--include("egd.hrl").
+-include("../include/egd.hrl").
%% Font represenatation in ets table
%% egd_font_table
@@ -56,12 +56,6 @@
%%==========================================================================
size(Font) ->
- case ets:info(egd_font_table) of
- undefined->
- Filename = filename:join([code:priv_dir(percept2),"fonts", "6x11_latin1.wingsfont"]),
- egd_font:load(Filename);
- _ -> ok
- end,
[{_Key, _Description, Size}] = ets:lookup(egd_font_table,{Font,information}),
Size.
View
@@ -26,7 +26,7 @@
-export([eps/1]).
-compile(inline).
--include("egd.hrl").
+-include("../include/egd.hrl").
-define('DummyC',0).
binary(Image) ->
View
@@ -231,6 +231,8 @@ start_webserver(Port) when is_integer(Port) ->
_ ->
ets:delete_all_objects(history_html)
end,
+ Filename = filename:join([code:priv_dir(percept2),"fonts", "6x11_latin1.wingsfont"]),
+ egd_font:load(Filename),
{started, Host, AssignedPort};
{error, Reason} ->
{error, {inets, Reason}}
@@ -267,6 +269,7 @@ do_stop(Port, Pid)->
Pid2 ->
Pid ! quit,
rm_tmp_files(),
+ ets:delete(egd_font_table),
inets:stop(httpd, Pid2)
end.
View
@@ -29,6 +29,7 @@
-record(graph_area, {x = 0, y = 0, width, height}).
+-compile(export_all).
-compile(inline).
-include("../include/percept2.hrl").
@@ -67,7 +68,7 @@ graph(Width, Height, Data) ->
error_graph(Width, Height, Text) ->
%% Initiate Image
Image = egd:create(round(Width/2), round(Height/2)),
- Font = load_font(),
+ Font = get_font(),
egd:text(Image, {200, 100}, Font, Text, egd:color(Image, {255, 0, 0})),
Binary = egd:render(Image, png),
egd:destroy(Image),
@@ -154,7 +155,7 @@ draw_xticks(Image, Color, XticksArea, {Xmin, Xmax}, Data) ->
DX = Width/(Xmax - Xmin),
Offset = X0 - Xmin*DX,
Y = trunc(Y0),
- Font = load_font(),
+ Font = get_font(),
{FontW, _FontH} = egd_font:size(Font),
egd:filledRectangle(Image, {trunc(X0), Y}, {trunc(X0 + Width), Y}, Color),
lists:foldl(
@@ -186,7 +187,7 @@ draw_xticks(Image, Color, XticksArea, {Xmin, Xmax}, Data) ->
draw_yticks(Im, Color, TickArea, {_,Ymax}) ->
#graph_area{x = X0, y = Y0, width = Width, height = Height} = TickArea,
- Font = load_font(),
+ Font = get_font(),
X = trunc(X0 + Width),
Dy = (Height)/(Ymax),
Yts = if
@@ -310,8 +311,8 @@ proc_lifetime(Width, Height, Start, End, ProfileTime) ->
%%% Percentage should be 0.0 -> 1.0
%%% -------------------------------------
percentage(Width, Height, Percentage) ->
+ Font = get_font(),
Im = egd:create(round(Width), round(Height)),
- Font = load_font(),
Black = egd:color(Im, {0, 0, 0}),
Green = egd:color(Im, {0, 255, 0}),
@@ -338,7 +339,7 @@ percentage(Width, Height, Percentage) ->
calltime_percentage(Width, Height, CallTime, Percentage) ->
Im = egd:create(round(Width), round(Height)),
- Font = load_font(),
+ Font = get_font(),
Black = egd:color(Im, {0, 0, 0}),
Green = egd:color(Im, {0, 255, 0}),
Grey = egd:color(Im, {128, 128, 128}),
@@ -361,10 +362,10 @@ calltime_percentage(Width, Height, CallTime, Percentage) ->
Binary.
-load_font() ->
- Filename = filename:join([code:priv_dir(percept2),"fonts", "6x11_latin1.wingsfont"]),
- egd_font:load(Filename).
-
+get_font() ->
+ {Font, _} =ets:first(egd_font_table),
+ Font.
+
text(Image, {X,Y}, Font, Text, Color) ->
egd:text(Image, {X,Y-2}, Font, Text, Color).

0 comments on commit 6c1df09

Please sign in to comment.