1 {
2 *****************************************************************************
3 *                                                                           *
4 *  This file is part of the ZCAD                                            *
5 *                                                                           *
6 *  See the file COPYING.modifiedLGPL.txt, included in this distribution,    *
7 *  for details about the copyright.                                         *
8 *                                                                           *
9 *  This program is distributed in the hope that it will be useful,          *
10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     *
12 *                                                                           *
13 *****************************************************************************
14 }
15 {
16 @author(Andrey Zubarev <zamtmn@yandex.ru>)
17 }
18 
19 unit uzestylestexts;
20 {$INCLUDE def.inc}
21 interface
22 uses LCLProc,uzbpaths,uzefontmanager,uzbtypesbase,sysutils,uzbtypes,uzegeometry,
23      uzbstrproc,uzefont,uzestrconsts,UGDBNamedObjectsArray,uzbmemman;
24 type
25   //ptextstyle = ^textstyle;
26 {REGISTEROBJECTTYPE GDBTextStyleArray}
27 {EXPORT+}
28 PGDBTextStyleProp=^GDBTextStyleProp;
29   GDBTextStyleProp=packed record
30                     size:GDBDouble;(*saved_to_shd*)
31                     oblique:GDBDouble;(*saved_to_shd*)
32                     wfactor:GDBDouble;(*saved_to_shd*)
33               end;
34   PPGDBTextStyleObjInsp=^PGDBTextStyleObjInsp;
35   PGDBTextStyleObjInsp=GDBPointer;
36   PGDBTextStyle=^GDBTextStyle;
37   GDBTextStyle = {$IFNDEF DELPHI}packed{$ENDIF}object(GDBNamedObject)
38     dxfname: GDBAnsiString;(*saved_to_shd*)
39     pfont: PGDBfont;
40     prop:GDBTextStyleProp;(*saved_to_shd*)
41     UsedInLTYPE:GDBBoolean;
42     destructor Done;virtual;
43   end;
44 PGDBTextStyleArray=^GDBTextStyleArray;
45 GDBTextStyleArray={$IFNDEF DELPHI}packed{$ENDIF} object(GDBNamedObjectsArray{-}<PGDBTextStyle,GDBTextStyle>{//})(*OpenArrayOfData=GDBTextStyle*)
46                     constructor init({$IFDEF DEBUGBUILD}ErrGuid:pansichar;{$ENDIF}m:GDBInteger);
47                     constructor initnul;
48 
addstylenull49                     function addstyle(StyleName,FontFile:GDBString;tp:GDBTextStyleProp;USedInLT:GDBBoolean):PGDBTextStyle;
setstylenull50                     function setstyle(StyleName,FontFile:GDBString;tp:GDBTextStyleProp;USedInLT:GDBBoolean):PGDBTextStyle;
FindStylenull51                     function FindStyle(StyleName:GDBString;ult:GDBBoolean):PGDBTextStyle;
52                     procedure freeelement(PItem:PT);virtual;
53               end;
54 {EXPORT-}
55 implementation
56 destructor GDBTextStyle.Done;
57 begin
58      inherited;
59      dxfname:='';
60 end;
61 procedure GDBTextStyleArray.freeelement;
62 begin
63   PGDBTextStyle(PItem).name:='';
64   PGDBTextStyle(PItem).dxfname:='';
65 end;
66 constructor GDBTextStyleArray.initnul;
67 begin
68   inherited initnul;
69   //objsizeof:=sizeof(GDBTextStyle);
70   //size:=sizeof(GDBTextStyle);
71 end;
72 constructor GDBTextStyleArray.init;
73 begin
74   //Size := sizeof(GDBTextStyle);
75   inherited init({$IFDEF DEBUGBUILD}ErrGuid,{$ENDIF}m{,sizeof(GDBTextStyle)});
76   //addlayer('0',cgdbwhile,lwgdbdefault);
77 end;
78 
79 {procedure GDBLayerArray.clear;
80 var i:GDBInteger;
81     tlp:PGDBLayerProp;
82 begin
83      if count>0 then
84      begin
85           tlp:=parray;
86           for i:=0 to count-1 do
87           begin
88                tlp^.name:='';
89                inc(tlp);
90           end;
91      end;
92   count:=0;
93 end;}
94 {function GDBLayerArray.getLayerIndex(name: GDBString): GDBInteger;
95 var
96   i: GDBInteger;
97 begin
98   result := 0;
99   for i := 0 to count - 1 do
100     if PGDBLayerPropArray(Parray)^[i].name = name then
101     begin
102       result := i;
103       exit;
104     end;
105 end;}
GDBTextStyleArray.setstylenull106 function GDBTextStyleArray.setstyle(StyleName,FontFile:GDBString;tp:GDBTextStyleProp;USedInLT:GDBBoolean):PGDBTextStyle;
107 var
108    ps:PGDBTextStyle;
109 begin
110   ps:=(FindStyle(StyleName,USedInLT));
111   ps.name:=stylename;
112   ps.dxfname:=FontFile;
113   ps.UsedInLTYPE:=USedInLT;
114 
115   if pos('.',FontFile)=0 then
116                              FontFile:=FontFile+'.shx';
117 
118   ps.pfont:=FontManager.addFonf(FindInPaths(sysvarPATHFontsPath,FontFile));
119   if not assigned(ps.pfont) then
120                                 begin
121                                      debugln('{WH}'+fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile]);
122                                      //programlog.LogOutFormatStr(fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile],lp_OldPos,LM_Debug);
123                                      //uzcshared.LogError(sysutils.format(fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile]));
124                                      ps.pfont:=pbasefont;
125                                 end;
126 
127   //ps.pfont:=FontManager.addFonf(FontFile);
128   //ps.pfont:=FontManager.{FindFonf}getAddres(FontFile);
129   //if ps.pfont=nil then ps.pfont:=FontManager.getAddres('normal.shx');
130   ps.prop:=tp;
131   result:=ps;
132   //result:=add(@ts);
133   //pointer(ts.name):=nil;
134   //pointer(ts.dxfname):=nil;
135 end;
GDBTextStyleArray.addstylenull136 function GDBTextStyleArray.addstyle(StyleName,FontFile:GDBString;tp:GDBTextStyleProp;USedInLT:GDBBoolean):{GDBInteger}PGDBTextStyle;
137 var ts:PGDBTextStyle;
138     //ff:gdbstring;
139     //p:GDBPointer;
140 begin
141   GDBGetmem({$IFDEF DEBUGBUILD}'{ED59B789-33EF-487E-9E1D-711F5988A194}',{$ENDIF}pointer(ts),sizeof(GDBTextStyle));
142   ts.init(stylename);
143   //ts.name:=stylename;
144   ts.dxfname:=FontFile;
145   ts.UsedInLTYPE:=USedInLT;
146 
147   if pos('.',FontFile)=0 then
148                              FontFile:=FontFile+'.shx';
149 
150   ts.pfont:=FontManager.addFonf(FindInPaths(sysvarPATHFontsPath,FontFile));
151   if not assigned(ts.pfont) then
152                                 begin
153                                      debugln('{WH}'+fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile]);
154                                      //programlog.LogOutFormatStr(fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile],lp_OldPos,LM_Debug);
155                                      //uzcshared.LogError(sysutils.format(fontnotfoundandreplace,[Tria_AnsiToUtf8(stylename),FontFile]));
156                                      ts.pfont:=pbasefont;
157                                 end;
158 
159   //ts.pfont:=FontManager.addFonf(FontFile);
160   //ts.pfont:=FontManager.{FindFonf}getAddres(FontFile);
161   //if ts.pfont=nil then ts.pfont:=FontManager.getAddres('normal.shx');
162   ts.prop:=tp;
163   result:=pointer(getDataMutable(PushBackData(ts)));
164   //pointer(ts.name):=nil;
165   //pointer(ts.dxfname):=nil;
166 end;
GDBTextStyleArray.FindStylenull167 function GDBTextStyleArray.FindStyle;
168 begin
169 
170   result:=getAddres(stylename);
171   if result<>nil then
172                   if result^.UsedInLTYPE<>ult then
173                                                result:=nil;
174   {StyleName:=uppercase(StyleName);
175   result:=nil;
176   if count=0 then exit;
177   result:=parray;
178   for i:=0 to count-1 do
179   begin
180         if (uppercase(result^.name)=stylename)and(result^.UsedInLTYPE=ult) then begin
181                                        result:=result;
182                                        exit;
183                                   end;
184        inc(result);
185   end;}
186 end;
187 
188 {function GDBLayerArray.CalcCopactMemSize2;
189 var i:GDBInteger;
190     tlp:PGDBLayerProp;
191 begin
192      result:=0;
193      objcount:=count;
194      if count=0 then exit;
195      result:=result;
196      tlp:=parray;
197      for i:=0 to count-1 do
198      begin
199           result:=result+sizeof(GDBByte)+sizeof(GDBSmallint)+sizeof(GDBWord)+length(tlp^.name);
200           inc(tlp);
201      end;
202 end;
203 function GDBLayerArray.SaveToCompactMemSize2;
204 var i:GDBInteger;
205     tlp:PGDBLayerProp;
206 begin
207      result:=0;
208      if count=0 then exit;
209      tlp:=parray;
210      for i:=0 to count-1 do
211      begin
212           PGDBByte(pmem)^:=tlp^.color;
213           inc(PGDBByte(pmem));
214           PGDBSmallint(pmem)^:=tlp^.lineweight;
215           inc(PGDBSmallint(pmem));
216           PGDBWord(pmem)^:=length(tlp^.name);
217           inc(PGDBWord(pmem));
218           Move(GDBPointer(tlp.name)^, pmem^,length(tlp.name));
219           inc(PGDBByte(pmem),length(tlp.name));
220           inc(tlp);
221      end;
222 end;
223 function GDBLayerArray.LoadCompactMemSize2;
224 begin
225      {inherited LoadCompactMemSize(pmem);
226      Coord:=PGDBLineProp(pmem)^;
227      inc(PGDBLineProp(pmem));
228      PProjPoint:=nil;
229      format;}
230 //end;
231 begin
232 end.
233