_falomGeneric.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* omGeneric.c 1.9 - Fujitsu source for CDEnext 96/04/26 11:20:11 */
  24. /* $XConsortium: _falomGeneric.c /main/4 1996/09/27 19:03:50 drk $ */
  25. /*
  26. * Copyright 1992, 1993 by TOSHIBA Corp.
  27. *
  28. * Permission to use, copy, modify, and distribute this software and its
  29. * documentation for any purpose and without fee is hereby granted, provided
  30. * that the above copyright notice appear in all copies and that both that
  31. * copyright notice and this permission notice appear in supporting
  32. * documentation, and that the name of TOSHIBA not be used in advertising
  33. * or publicity pertaining to distribution of the software without specific,
  34. * written prior permission. TOSHIBA make no representations about the
  35. * suitability of this software for any purpose. It is provided "as is"
  36. * without express or implied warranty.
  37. *
  38. * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  39. * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  40. * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  41. * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  42. * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  43. * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  44. * SOFTWARE.
  45. *
  46. * Author: Katsuhisa Yano TOSHIBA Corp.
  47. * mopi@osa.ilab.toshiba.co.jp
  48. */
  49. /*
  50. * Copyright 1995 by FUJITSU LIMITED
  51. * This is source code modified by FUJITSU LIMITED under the Joint
  52. * Development Agreement for the CDEnext PST.
  53. * This is unpublished proprietary source code of FUJITSU LIMITED
  54. *
  55. * Modifier: Takanori Tateno FUJITSU LIMITED
  56. *
  57. */
  58. #include "_fallibint.h"
  59. #include "_falomGeneric.h"
  60. #include <X11/Xos.h>
  61. #include <X11/Xatom.h>
  62. #include <stdio.h>
  63. #include <string.h>
  64. #include <ctype.h>
  65. #define MAXFONTS 100
  66. #define PIXEL_SIZE_FIELD 7
  67. #define POINT_SIZE_FIELD 8
  68. #define CHARSET_ENCODING_FIELD 14
  69. extern int _falmbDefaultTextEscapement(), _falwcDefaultTextEscapement();
  70. extern int _falmbDefaultTextExtents(), _falwcDefaultTextExtents();
  71. extern Status _falmbDefaultTextPerCharExtents(), _falwcDefaultTextPerCharExtents();
  72. extern int _falmbDefaultDrawString(), _falwcDefaultDrawString();
  73. extern void _falmbDefaultDrawImageString(), _falwcDefaultDrawImageString();
  74. extern int _falmbGenericTextEscapement(), _falwcGenericTextEscapement();
  75. extern int _falmbGenericTextExtents(), _falwcGenericTextExtents();
  76. extern Status _falmbGenericTextPerCharExtents(), _falwcGenericTextPerCharExtents();
  77. extern int _falmbGenericDrawString(), _falwcGenericDrawString();
  78. extern void _falmbGenericDrawImageString(), _falwcGenericDrawImageString();
  79. extern void dbg_printValue(char *str, char **value, int num);
  80. /* For VW/UDC start */
  81. static FontData
  82. init_fontdata(FontData font_data, int font_data_count)
  83. {
  84. FontData fd;
  85. int i;
  86. fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count);
  87. if(fd == (FontData) NULL)
  88. return False;
  89. memset(fd, 0x00, sizeof(FontData) * font_data_count);
  90. for(i = 0 ; i < font_data_count ; i++)
  91. fd[i] = font_data[i];
  92. return fd;
  93. }
  94. static VRotate
  95. init_vrotate(
  96. FontData font_data,
  97. int font_data_count,
  98. int type,
  99. CodeRange code_range,
  100. int code_range_num)
  101. {
  102. VRotate vrotate;
  103. int i;
  104. if(type == VROTATE_NONE)
  105. return (VRotate)NULL;
  106. vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count);
  107. if(vrotate == (VRotate) NULL)
  108. return False;
  109. memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count);
  110. for(i = 0 ; i < font_data_count ; i++) {
  111. vrotate[i].charset_name = font_data[i].name;
  112. vrotate[i].side = font_data[i].side;
  113. if(type == VROTATE_PART) {
  114. vrotate[i].num_cr = code_range_num;
  115. vrotate[i].code_range = code_range;
  116. }
  117. }
  118. return vrotate;
  119. }
  120. static Bool
  121. init_fontset(XOC oc)
  122. {
  123. XOCGenericPart *gen;
  124. FontSet font_set;
  125. OMData data;
  126. int count;
  127. int err = 0;
  128. count = XOM_GENERIC(oc->core.om)->data_num;
  129. data = XOM_GENERIC(oc->core.om)->data;
  130. font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count);
  131. if (font_set == NULL)
  132. return False;
  133. memset((char *) font_set, 0x00, sizeof(FontSetRec) * count);
  134. gen = XOC_GENERIC(oc);
  135. gen->font_set_num = count;
  136. gen->font_set = font_set;
  137. for ( ; count-- > 0; data++, font_set++) {
  138. font_set->charset_count = data->charset_count;
  139. font_set->charset_list = data->charset_list;
  140. if((font_set->font_data = init_fontdata(data->font_data,
  141. data->font_data_count)) == NULL){
  142. err += 1;
  143. break;
  144. }
  145. font_set->font_data_count = data->font_data_count;
  146. if((font_set->substitute = init_fontdata(data->substitute,
  147. data->substitute_num)) == NULL){
  148. err += 1;
  149. break;
  150. }
  151. font_set->substitute_num = data->substitute_num;
  152. if((font_set->vmap = init_fontdata(data->vmap,
  153. data->vmap_num)) == NULL){
  154. err += 1;
  155. break;
  156. }
  157. font_set->vmap_num = data->vmap_num;
  158. if(data->vrotate_type != VROTATE_NONE) {
  159. /* A vrotate member is specified primary font data */
  160. /* as initial value. */
  161. if((font_set->vrotate = init_vrotate(data->font_data,
  162. data->font_data_count,
  163. data->vrotate_type,
  164. data->vrotate,
  165. data->vrotate_num)) == NULL){
  166. err += 1;
  167. break;
  168. }
  169. font_set->vrotate_num = data->font_data_count;
  170. }
  171. }
  172. if (err == 1){
  173. if(font_set->font_data)
  174. Xfree(font_set->font_data);
  175. if(font_set->substitute)
  176. Xfree(font_set->substitute);
  177. if(font_set->vmap)
  178. Xfree(font_set->vmap);
  179. if(font_set->vrotate)
  180. Xfree(font_set->vrotate);
  181. if(font_set)
  182. Xfree(font_set);
  183. gen->font_set = (FontSet) NULL;
  184. gen->font_set_num = 0;
  185. return False;
  186. } else {
  187. return True;
  188. }
  189. }
  190. /* For VW/UDC end */
  191. static char *
  192. get_prop_name(Display *dpy, XFontStruct *fs)
  193. {
  194. unsigned long fp;
  195. if (falGetFontProperty(fs, XA_FONT, &fp))
  196. return falGetAtomName(dpy, fp);
  197. return (char *) NULL;
  198. }
  199. static FontData
  200. check_charset(FontSet font_set, char *font_name)
  201. {
  202. FontData font_data;
  203. char *last;
  204. int count, length, name_len;
  205. name_len = strlen(font_name);
  206. last = font_name + name_len;
  207. count = font_set->font_data_count;
  208. font_data = font_set->font_data;
  209. for ( ; count-- > 0; font_data++) {
  210. length = strlen(font_data->name);
  211. if (length > name_len)
  212. continue;
  213. if (_fallcCompareISOLatin1(last - length, font_data->name) == 0)
  214. return font_data;
  215. }
  216. return (FontData) NULL;
  217. }
  218. static int
  219. check_fontname(XOC oc, char *name, int found_num)
  220. {
  221. Display *dpy = oc->core.om->core.display;
  222. XOCGenericPart *gen = XOC_GENERIC(oc);
  223. FontData data;
  224. FontSet font_set;
  225. XFontStruct *fs_list;
  226. char **fn_list, *fname, *prop_fname = NULL;
  227. int list_num, font_set_num, i;
  228. int list2_num;
  229. char **fn2_list = NULL;
  230. fn_list = falListFonts(dpy, name, MAXFONTS, &list_num);
  231. if (fn_list == NULL)
  232. return found_num;
  233. for (i = 0; i < list_num; i++) {
  234. fname = fn_list[i];
  235. font_set = gen->font_set;
  236. font_set_num = gen->font_set_num;
  237. for ( ; font_set_num-- > 0; font_set++) {
  238. if (font_set->font_name)
  239. continue;
  240. if ((data = check_charset(font_set, fname)) == NULL) {
  241. if ((fn2_list = falListFontsWithInfo(dpy, name, MAXFONTS,
  242. &list2_num, &fs_list))
  243. && (prop_fname = get_prop_name(dpy, fs_list))
  244. && (data = check_charset(font_set, prop_fname)))
  245. fname = prop_fname;
  246. }
  247. if (data) {
  248. font_set->side = data->side;
  249. font_set->font_name = (char *) Xmalloc(strlen(fname) + 1);
  250. if (font_set->font_name) {
  251. strcpy(font_set->font_name, fname);
  252. found_num++;
  253. }
  254. }
  255. if (fn2_list) {
  256. falFreeFontInfo(fn2_list, fs_list, list2_num);
  257. fn2_list = NULL;
  258. if (prop_fname) {
  259. Xfree(prop_fname);
  260. prop_fname = NULL;
  261. }
  262. }
  263. if (found_num == gen->font_set_num)
  264. break;
  265. }
  266. }
  267. falFreeFontNames(fn_list);
  268. return found_num;
  269. }
  270. /* For VW/UDC start */
  271. static Bool
  272. load_fontdata(XOC oc, FontData font_data, int font_data_num)
  273. {
  274. Display *dpy = oc->core.om->core.display;
  275. FontData fd = font_data;
  276. for( ; font_data_num-- ; fd++) {
  277. if(fd->xlfd_name != (char *) NULL && fd->font == NULL) {
  278. fd->font = falLoadQueryFont(dpy, fd->xlfd_name);
  279. if (fd->font == NULL)
  280. return False;
  281. }
  282. }
  283. return True;
  284. }
  285. static Bool
  286. load_font(XOC oc)
  287. {
  288. int i;
  289. XOCGenericPart *gen = XOC_GENERIC(oc);
  290. FontSet font_set = gen->font_set;
  291. int num = gen->font_set_num;
  292. for ( ; num-- > 0; font_set++) {
  293. if (font_set->font_name == NULL)
  294. continue;
  295. if(load_fontdata(oc, font_set->font_data,
  296. font_set->font_data_count) != True)
  297. return False;
  298. if(load_fontdata(oc, font_set->substitute,
  299. font_set->substitute_num) != True)
  300. return False;
  301. if(font_set->font_data_count > 0 && font_set->font_data->font) {
  302. font_set->font = font_set->font_data->font;
  303. } else if(font_set->substitute_num > 0 ) {
  304. for(i=0;i<font_set->substitute_num;i++){
  305. if(font_set->substitute[i].font != NULL){
  306. font_set->font = font_set->substitute[i].font;
  307. }
  308. }
  309. }
  310. load_fontdata(oc, font_set->vmap, font_set->vmap_num);
  311. load_fontdata(oc, (FontData) font_set->vrotate,
  312. font_set->vrotate_num);
  313. if (font_set->font->min_byte1 || font_set->font->max_byte1)
  314. font_set->is_xchar2b = True;
  315. else
  316. font_set->is_xchar2b = False;
  317. }
  318. return True;
  319. }
  320. /* For VW/UDC end */
  321. static Bool
  322. load_font_info(XOC oc)
  323. {
  324. Display *dpy = oc->core.om->core.display;
  325. XOCGenericPart *gen = XOC_GENERIC(oc);
  326. FontSet font_set = gen->font_set;
  327. char **fn_list;
  328. int fn_num, num = gen->font_set_num;
  329. for ( ; num-- > 0; font_set++) {
  330. if (font_set->font_name == NULL)
  331. continue;
  332. if (font_set->info == NULL) {
  333. fn_list = falListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
  334. &font_set->info);
  335. if (font_set->info == NULL)
  336. return False;
  337. falFreeFontNames(fn_list);
  338. }
  339. }
  340. return True;
  341. }
  342. /* For Vertical Writing start */
  343. static void
  344. check_fontset_extents(
  345. XCharStruct *overall,
  346. int *logical_ascent,
  347. int *logical_descent,
  348. XFontStruct *font)
  349. {
  350. overall->lbearing = min(overall->lbearing, font->min_bounds.lbearing);
  351. overall->rbearing = max(overall->rbearing, font->max_bounds.rbearing);
  352. overall->ascent = max(overall->ascent, font->max_bounds.ascent);
  353. overall->descent = max(overall->descent, font->max_bounds.descent);
  354. overall->width = max(overall->width, font->max_bounds.width);
  355. *logical_ascent = max(*logical_ascent, font->ascent);
  356. *logical_descent = max(*logical_descent, font->descent);
  357. }
  358. /* For Vertical Writing end */
  359. static void
  360. set_fontset_extents(XOC oc)
  361. {
  362. XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
  363. XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
  364. XFontStruct **font_list, *font;
  365. XCharStruct overall;
  366. int logical_ascent, logical_descent;
  367. int num = oc->core.font_info.num_font;
  368. font_list = oc->core.font_info.font_struct_list;
  369. font = *font_list++;
  370. overall = font->max_bounds;
  371. overall.lbearing = font->min_bounds.lbearing;
  372. logical_ascent = font->ascent;
  373. logical_descent = font->descent;
  374. /* For Vertical Writing start */
  375. while (--num > 0) {
  376. font = *font_list++;
  377. check_fontset_extents(&overall, &logical_ascent, &logical_descent,
  378. font);
  379. }
  380. {
  381. XOCGenericPart *gen = XOC_GENERIC(oc);
  382. FontSet font_set = gen->font_set;
  383. FontData font_data;
  384. int font_set_num = gen->font_set_num;
  385. int font_data_count;
  386. for( ; font_set_num-- ; font_set++) {
  387. if(font_set->vmap_num > 0) {
  388. font_data = font_set->vmap;
  389. font_data_count = font_set->vmap_num;
  390. for( ; font_data_count-- ; font_data++) {
  391. if(font_data->font != NULL) {
  392. check_fontset_extents(&overall, &logical_ascent,
  393. &logical_descent,
  394. font_data->font);
  395. }
  396. }
  397. }
  398. #ifndef COMMENT
  399. if(font_set->vrotate_num > 0) {
  400. font_data = (FontData) font_set->vrotate;
  401. font_data_count = font_set->vrotate_num;
  402. for( ; font_data_count-- ; font_data++) {
  403. if(font_data->font != NULL) {
  404. check_fontset_extents(&overall, &logical_ascent,
  405. &logical_descent,
  406. font_data->font);
  407. }
  408. }
  409. }
  410. #endif /* COMMENT */
  411. }
  412. }
  413. /* For Vertical Writing start */
  414. ink->x = overall.lbearing;
  415. ink->y = -(overall.ascent);
  416. ink->width = overall.rbearing - overall.lbearing;
  417. ink->height = overall.ascent + overall.descent;
  418. logical->x = 0;
  419. logical->y = -(logical_ascent);
  420. logical->width = overall.width;
  421. logical->height = logical_ascent + logical_descent;
  422. }
  423. static Bool
  424. init_core_part(XOC oc)
  425. {
  426. XOCGenericPart *gen = XOC_GENERIC(oc);
  427. FontSet font_set;
  428. int font_set_num;
  429. XFontStruct **font_struct_list;
  430. char **font_name_list, *font_name_buf;
  431. int count, length;
  432. font_set = gen->font_set;
  433. font_set_num = gen->font_set_num;
  434. count = length = 0;
  435. for ( ; font_set_num-- > 0; font_set++) {
  436. if (font_set->font_name == NULL)
  437. continue;
  438. length += strlen(font_set->font_name) + 1;
  439. count++;
  440. }
  441. if (count == 0)
  442. return False;
  443. font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count);
  444. if (font_struct_list == NULL)
  445. return False;
  446. font_name_list = (char **) Xmalloc(sizeof(char *) * count);
  447. if (font_name_list == NULL){
  448. if (font_name_list)
  449. Xfree(font_name_list);
  450. Xfree(font_struct_list);
  451. return False;
  452. }
  453. font_name_buf = (char *) Xmalloc(length);
  454. if (font_name_buf == NULL){
  455. if (font_name_list)
  456. Xfree(font_name_list);
  457. Xfree(font_struct_list);
  458. return False;
  459. }
  460. oc->core.font_info.num_font = count;
  461. oc->core.font_info.font_name_list = font_name_list;
  462. oc->core.font_info.font_struct_list = font_struct_list;
  463. font_set = gen->font_set;
  464. font_set_num = gen->font_set_num;
  465. for (count = 0; font_set_num-- > 0; font_set++, count++) {
  466. if (font_set->font_name == NULL)
  467. continue;
  468. font_set->id = count;
  469. if (font_set->font)
  470. *font_struct_list++ = font_set->font;
  471. else
  472. *font_struct_list++ = font_set->info;
  473. strcpy(font_name_buf, font_set->font_name);
  474. Xfree(font_set->font_name);
  475. *font_name_list++ = font_set->font_name = font_name_buf;
  476. font_name_buf += strlen(font_name_buf) + 1;
  477. }
  478. set_fontset_extents(oc);
  479. return True;
  480. }
  481. static char *
  482. get_font_name(XOC oc, char *pattern)
  483. {
  484. char **list, *name;
  485. int count = 0;
  486. list = falListFonts(oc->core.om->core.display, pattern, 1, &count);
  487. if (list == NULL)
  488. return NULL;
  489. name = (char *) Xmalloc(strlen(*list) + 1);
  490. if (name)
  491. strcpy(name, *list);
  492. falFreeFontNames(list);
  493. return name;
  494. }
  495. /* For VW/UDC start*/
  496. static char
  497. *get_rotate_fontname(char *font_name)
  498. {
  499. char *pattern = NULL, *ptr = NULL;
  500. char *fields[CHARSET_ENCODING_FIELD];
  501. char str_pixel[32], str_point[4];
  502. char rotate_font[256];
  503. char *rotate_font_ptr = NULL;
  504. int pixel_size = 0;
  505. int field_num = 0, len = 0;
  506. if(font_name == (char *) NULL || (len = strlen(font_name)) <= 0)
  507. return NULL;
  508. pattern = (char *)Xmalloc(len + 1);
  509. if(!pattern)
  510. return NULL;
  511. strcpy(pattern, font_name);
  512. memset(fields, 0, sizeof(char *) * 14);
  513. ptr = pattern;
  514. while(isspace(*ptr)) {
  515. ptr++;
  516. }
  517. if(*ptr == '-')
  518. ptr++;
  519. for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && ptr && *ptr ;
  520. ptr++, field_num++) {
  521. fields[field_num] = ptr;
  522. if(ptr = strchr(ptr, '-')) {
  523. *ptr = '\0';
  524. }
  525. }
  526. if(field_num < CHARSET_ENCODING_FIELD) {
  527. Xfree(pattern);
  528. return NULL;
  529. }
  530. /* Pixel Size field : fields[6] */
  531. for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) {
  532. if(!isdigit(*ptr)) {
  533. Xfree(pattern);
  534. return NULL;
  535. }
  536. }
  537. pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]);
  538. snprintf(str_pixel, sizeof(str_pixel), "[ 0 ~%d %d 0 ]", pixel_size, pixel_size);
  539. fields[6] = str_pixel;
  540. /* Point Size field : fields[7] */
  541. strcpy(str_point, "*");
  542. fields[POINT_SIZE_FIELD - 1] = str_point;
  543. rotate_font[0] = '\0';
  544. for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD &&
  545. fields[field_num] ; field_num++) {
  546. snprintf(rotate_font, sizeof(rotate_font), "%s-%s", rotate_font, fields[field_num]);
  547. }
  548. if(pattern)
  549. Xfree(pattern);
  550. rotate_font_ptr = (char *)Xmalloc(strlen(rotate_font) + 1);
  551. if(!rotate_font_ptr)
  552. return NULL;
  553. strcpy(rotate_font_ptr, rotate_font);
  554. return rotate_font_ptr;
  555. }
  556. static Bool
  557. is_match_charset(FontData font_data, char *font_name)
  558. {
  559. char *last;
  560. int length, name_len;
  561. name_len = strlen(font_name);
  562. last = font_name + name_len;
  563. length = strlen(font_data->name);
  564. if (length > name_len)
  565. return False;
  566. if (_fallcCompareISOLatin1(last - length, font_data->name) == 0)
  567. return True;
  568. return False;
  569. }
  570. static int
  571. parse_all_name(XOC oc, FontData font_data, char *pattern)
  572. {
  573. if(is_match_charset(font_data, pattern) != True)
  574. return False;
  575. font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
  576. if(font_data->xlfd_name == NULL)
  577. return (-1);
  578. strcpy(font_data->xlfd_name, pattern);
  579. return True;
  580. }
  581. static int
  582. parse_omit_name(XOC oc, FontData font_data, char *pattern)
  583. {
  584. char *font_name = (char *) NULL;
  585. char *last = (char *) NULL;
  586. char buf[BUFSIZE];
  587. int length = 0;
  588. if(is_match_charset(font_data, pattern) == True) {
  589. strcpy(buf, pattern);
  590. if (font_name = get_font_name(oc, buf)) {
  591. font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
  592. if(font_data->xlfd_name == NULL) {
  593. Xfree(font_name);
  594. return (-1);
  595. }
  596. strcpy(font_data->xlfd_name, font_name);
  597. Xfree(font_name);
  598. return True;
  599. }
  600. }
  601. snprintf(buf, sizeof(buf), "%s", pattern);
  602. length = strlen(pattern);
  603. last = buf + length - 1;
  604. if (length > 1 && *last == '*' && *(last - 1) == '-') {
  605. if (length > 3 && *(last - 2) == '*' && *(last - 3) == '-')
  606. last -= 2;
  607. } else {
  608. ++last;
  609. *last++ = '-';
  610. }
  611. strcpy(last, font_data->name);
  612. if (font_name = get_font_name(oc, buf)) {
  613. font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
  614. if(font_data->xlfd_name == NULL) {
  615. Xfree(font_name);
  616. return (-1);
  617. }
  618. strcpy(font_data->xlfd_name, font_name);
  619. Xfree(font_name);
  620. return True;
  621. }
  622. *last = '*';
  623. *(last + 1) = '-';
  624. strcpy(last + 2, font_data->name);
  625. if (font_name = get_font_name(oc, buf)) {
  626. font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
  627. if(font_data->xlfd_name == NULL) {
  628. Xfree(font_name);
  629. return (-1);
  630. }
  631. strcpy(font_data->xlfd_name, font_name);
  632. Xfree(font_name);
  633. return True;
  634. }
  635. return False;
  636. }
  637. typedef enum{C_PRIMARY, C_SUBSTITUTE, C_VMAP, C_VROTATE } ClassType;
  638. static int
  639. parse_fontdata(
  640. XOC oc,
  641. FontData font_data,
  642. int font_data_count,
  643. char **name_list,
  644. int name_list_count,
  645. ClassType class)
  646. {
  647. char **cur_name_list = name_list;
  648. char *font_name = (char *) NULL;
  649. char *pattern = (char *) NULL;
  650. int found_num = 0, ret = 0;
  651. int fd_count = font_data_count;
  652. int count = name_list_count;
  653. Bool is_found = False;
  654. if(name_list == NULL || count <= 0) {
  655. return False;
  656. }
  657. if(font_data == NULL || font_data_count <= 0) {
  658. return False;
  659. }
  660. for ( ; font_data_count-- > 0; font_data++) {
  661. is_found = False;
  662. font_name = (char *) NULL;
  663. count = name_list_count;
  664. cur_name_list = name_list;
  665. while (count-- > 0) {
  666. pattern = *cur_name_list++;
  667. if (pattern == NULL || *pattern == '\0')
  668. continue;
  669. /* When the font name is specified a full name. */
  670. if (strchr(pattern, '*') == NULL &&
  671. (font_name = get_font_name(oc, pattern))) {
  672. ret = parse_all_name(oc, font_data, font_name);
  673. Xfree(font_name);
  674. if(ret == -1)
  675. return ret;
  676. else if (ret == True) {
  677. found_num++;
  678. is_found = True;
  679. break;
  680. } else
  681. continue;
  682. }
  683. /* When the font name is specified a omited name. */
  684. ret = parse_omit_name(oc, font_data, pattern);
  685. if(ret == -1)
  686. return ret;
  687. else if (ret == True) {
  688. found_num++;
  689. is_found = True;
  690. break;
  691. } else
  692. continue;
  693. }
  694. switch(class) {
  695. case C_PRIMARY:
  696. if(is_found != True)
  697. return False;
  698. break;
  699. case C_SUBSTITUTE:
  700. case C_VMAP:
  701. if(is_found == True)
  702. return True;
  703. break;
  704. case C_VROTATE:
  705. if(is_found == True) {
  706. char *rotate_name;
  707. if((rotate_name = get_rotate_fontname(font_data->xlfd_name)) !=
  708. NULL) {
  709. Xfree(font_data->xlfd_name);
  710. font_data->xlfd_name = rotate_name;
  711. return True;
  712. }
  713. Xfree(font_data->xlfd_name);
  714. return False;
  715. }
  716. }
  717. }
  718. if(class == C_PRIMARY && found_num == fd_count)
  719. return True;
  720. return False;
  721. }
  722. static int
  723. parse_vw(XOC oc, FontSet font_set, char **name_list, int count)
  724. {
  725. FontData vmap = font_set->vmap;
  726. VRotate vrotate = font_set->vrotate;
  727. int vmap_num = font_set->vmap_num;
  728. int vrotate_num = font_set->vrotate_num;
  729. int ret = 0, i = 0;
  730. if(vmap_num > 0) {
  731. if(parse_fontdata(oc, vmap, vmap_num, name_list, count, C_VMAP) == -1)
  732. return (-1);
  733. }
  734. if(vrotate_num > 0) {
  735. ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num,
  736. name_list, count, C_VROTATE);
  737. if(ret == -1) {
  738. return (-1);
  739. } else if(ret == False) {
  740. CodeRange code_range;
  741. int num_cr;
  742. int sub_num = font_set->substitute_num;
  743. code_range = vrotate[i].code_range;
  744. num_cr = vrotate[i].num_cr;
  745. for(i = 0 ; i < vrotate_num ; i++) {
  746. if(vrotate[i].xlfd_name)
  747. Xfree(vrotate[i].xlfd_name);
  748. }
  749. Xfree(vrotate);
  750. if(sub_num > 0) {
  751. vrotate = font_set->vrotate = (VRotate)Xmalloc
  752. (sizeof(VRotateRec) * sub_num);
  753. if(font_set->vrotate == (VRotate)NULL)
  754. return (-1);
  755. for(i = 0 ; i < sub_num ; i++) {
  756. vrotate[i].charset_name = font_set->substitute[i].name;
  757. vrotate[i].side = font_set->substitute[i].side;
  758. vrotate[i].code_range = code_range;
  759. vrotate[i].num_cr = num_cr;
  760. }
  761. vrotate_num = font_set->vrotate_num = sub_num;
  762. } else {
  763. font_set->vrotate = (VRotate)NULL;
  764. }
  765. ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num,
  766. name_list, count, C_VROTATE);
  767. if(ret == -1)
  768. return (-1);
  769. }
  770. }
  771. return True;
  772. }
  773. static int
  774. parse_fontname(XOC oc)
  775. {
  776. XOCGenericPart *gen = XOC_GENERIC(oc);
  777. FontSet font_set;
  778. char *base_name, **name_list;
  779. int font_set_num = 0;
  780. int found_num = 0;
  781. int count = 0;
  782. int ret;
  783. int i;
  784. name_list = _falParseBaseFontNameList(oc->core.base_name_list, &count);
  785. if (name_list == NULL)
  786. return -1;
  787. font_set = gen->font_set;
  788. font_set_num = gen->font_set_num;
  789. for( ; font_set_num-- > 0 ; font_set++) {
  790. if(font_set->font_name)
  791. continue;
  792. if(font_set->font_data_count > 0) {
  793. ret = parse_fontdata(oc, font_set->font_data,
  794. font_set->font_data_count,
  795. name_list, count, C_PRIMARY);
  796. if(ret == -1) {
  797. falFreeStringList(name_list);
  798. return -1;
  799. } else if(ret == True) {
  800. font_set->font_name = (char *)Xmalloc
  801. (strlen(font_set->font_data->xlfd_name) + 1);
  802. if(font_set->font_name == (char *) NULL){
  803. falFreeStringList(name_list);
  804. return -1;
  805. }
  806. strcpy(font_set->font_name, font_set->font_data->xlfd_name);
  807. font_set->side = font_set->font_data->side;
  808. if(parse_vw(oc, font_set, name_list, count) == -1){
  809. falFreeStringList(name_list);
  810. return -1;
  811. }
  812. found_num++;
  813. /* The substitute font is serched, when the primary fonts */
  814. /* is not found. */
  815. } else {
  816. /* The primary information is free from FontSet structure */
  817. font_set->font_data_count = 0;
  818. if(font_set->font_data) {
  819. Xfree(font_set->font_data);
  820. font_set->font_data = (FontData) NULL;
  821. }
  822. /* A vrotate member is replaced to substitute information */
  823. /* from primary information. */
  824. font_set->vrotate_num = 0;
  825. if(font_set->vrotate) {
  826. Xfree(font_set->vrotate);
  827. font_set->vrotate = (VRotate) NULL;
  828. }
  829. ret = parse_fontdata(oc, font_set->substitute,
  830. font_set->substitute_num,
  831. name_list, count, C_SUBSTITUTE);
  832. if(ret == -1) {
  833. falFreeStringList(name_list);
  834. return -1;
  835. } else if(ret == True) {
  836. for(i=0;i<font_set->substitute_num;i++){
  837. if(font_set->substitute[i].xlfd_name != NULL){
  838. break;
  839. }
  840. }
  841. font_set->font_name = (char *)Xmalloc
  842. (strlen(font_set->substitute[i].xlfd_name) + 1);
  843. if(font_set->font_name == (char *) NULL){
  844. falFreeStringList(name_list);
  845. return -1;
  846. }
  847. strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
  848. font_set->side = font_set->substitute[i].side;
  849. if(parse_vw(oc, font_set, name_list, count) == -1){
  850. falFreeStringList(name_list);
  851. return -1;
  852. }
  853. found_num++;
  854. }
  855. }
  856. } else if(font_set->substitute_num > 0) {
  857. ret = parse_fontdata(oc, font_set->substitute,
  858. font_set->substitute_num,
  859. name_list, count, C_SUBSTITUTE);
  860. if(ret == -1) {
  861. falFreeStringList(name_list);
  862. return -1;
  863. } else if(ret == True) {
  864. for(i=0;i<font_set->substitute_num;i++){
  865. if(font_set->substitute[i].xlfd_name != NULL){
  866. break;
  867. }
  868. }
  869. font_set->font_name = (char *)Xmalloc
  870. (strlen(font_set->substitute[i].xlfd_name) + 1);
  871. if(font_set->font_name == (char *) NULL){
  872. falFreeStringList(name_list);
  873. return -1;
  874. }
  875. strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
  876. font_set->side = font_set->substitute[i].side;
  877. if(parse_vw(oc, font_set, name_list, count) == -1){
  878. falFreeStringList(name_list);
  879. return -1;
  880. }
  881. found_num++;
  882. }
  883. }
  884. }
  885. base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
  886. if (base_name == NULL){
  887. falFreeStringList(name_list);
  888. return -1;
  889. }
  890. strcpy(base_name, oc->core.base_name_list);
  891. oc->core.base_name_list = base_name;
  892. falFreeStringList(name_list);
  893. return found_num;
  894. }
  895. /* For VW/UDC end*/
  896. static Bool
  897. set_missing_list(XOC oc)
  898. {
  899. XOCGenericPart *gen = XOC_GENERIC(oc);
  900. FontSet font_set;
  901. char **charset_list, *charset_buf;
  902. int count, length, font_set_num;
  903. font_set = gen->font_set;
  904. font_set_num = gen->font_set_num;
  905. count = length = 0;
  906. for ( ; font_set_num-- > 0; font_set++) {
  907. if (font_set->info || font_set->font)
  908. continue;
  909. /* Change 1996.01.23 start */
  910. if(font_set->font_data_count <= 0 ||
  911. font_set->font_data == (FontData)NULL) {
  912. if(font_set->substitute_num <= 0 ||
  913. font_set->substitute == (FontData)NULL)
  914. if(font_set->charset_list != NULL){
  915. length +=
  916. strlen(font_set->charset_list[0]->encoding_name) + 1;
  917. } else {
  918. length += 1;
  919. }
  920. else
  921. length += strlen(font_set->substitute->name) + 1;
  922. } else {
  923. length += strlen(font_set->font_data->name) + 1;
  924. }
  925. /* Change 1996.01.23 end */
  926. count++;
  927. }
  928. if (count < 1)
  929. return True;
  930. charset_list = (char **) Xmalloc(sizeof(char *) * count);
  931. if (charset_list == NULL)
  932. return False;
  933. charset_buf = (char *) Xmalloc(length);
  934. if (charset_buf == NULL) {
  935. Xfree(charset_list);
  936. return False;
  937. }
  938. oc->core.missing_list.charset_list = charset_list;
  939. oc->core.missing_list.charset_count = count;
  940. font_set = gen->font_set;
  941. font_set_num = gen->font_set_num;
  942. for ( ; font_set_num-- > 0; font_set++) {
  943. if (font_set->info || font_set->font)
  944. continue;
  945. /* Change 1996.01.23 start */
  946. if(font_set->font_data_count <= 0 ||
  947. font_set->font_data == (FontData)NULL) {
  948. if(font_set->substitute_num <= 0 ||
  949. font_set->substitute == (FontData)NULL)
  950. if(font_set->charset_list != NULL){
  951. strcpy(charset_buf,
  952. font_set->charset_list[0]->encoding_name);
  953. } else {
  954. strcpy(charset_buf, "");
  955. }
  956. else
  957. strcpy(charset_buf, font_set->substitute->name);
  958. } else {
  959. strcpy(charset_buf, font_set->font_data->name);
  960. }
  961. /* Change 1996.01.23 end */
  962. *charset_list++ = charset_buf;
  963. charset_buf += strlen(charset_buf) + 1;
  964. }
  965. return True;
  966. }
  967. static Bool
  968. create_fontset(XOC oc)
  969. {
  970. XOMGenericPart *gen = XOM_GENERIC(oc->core.om);
  971. int found_num;
  972. if (init_fontset(oc) == False)
  973. return False;
  974. found_num = parse_fontname(oc);
  975. if (found_num <= 0) {
  976. if (found_num == 0)
  977. set_missing_list(oc);
  978. return False;
  979. }
  980. if (gen->on_demand_loading == True) {
  981. if (load_font_info(oc) == False)
  982. return False;
  983. } else {
  984. if (load_font(oc) == False)
  985. return False;
  986. }
  987. if (init_core_part(oc) == False)
  988. return False;
  989. if (set_missing_list(oc) == False)
  990. return False;
  991. return True;
  992. }
  993. /* For VW/UDC start */
  994. static void
  995. free_fontdataOC(Display *dpy, FontData font_data, int font_data_count)
  996. {
  997. for( ; font_data_count-- ; font_data++) {
  998. if(font_data->xlfd_name){
  999. Xfree(font_data->xlfd_name);
  1000. font_data->xlfd_name = NULL;
  1001. }
  1002. if(font_data->font){ /* ADD 1996.01.7 */
  1003. if(font_data->font->fid) /* Add 1996.01.23 */
  1004. falFreeFont(dpy,font_data->font); /* ADD 1996.01.7 */
  1005. else /* Add 1996.01.23 */
  1006. falFreeFontInfo(NULL, font_data->font, 1);/* Add 1996.01.23 */
  1007. font_data->font = NULL;
  1008. }
  1009. /* XOM to kyoutuu shite shiyou sushiteiru ryouiki
  1010. kokoha free_fontdataOM() de free sareru
  1011. if(font_data->scopes){
  1012. Xfree(font_data->scopes);
  1013. font_data->scopes = NULL;
  1014. }
  1015. if(font_data->name){
  1016. Xfree(font_data->name);
  1017. font_data->name = NULL;
  1018. }
  1019. */
  1020. }
  1021. }
  1022. static void
  1023. destroy_fontdata(XOCGenericPart *gen, Display *dpy)
  1024. {
  1025. FontSet font_set = (FontSet) NULL;
  1026. int font_set_num = 0;
  1027. if (gen->font_set) {
  1028. font_set = gen->font_set;
  1029. font_set_num = gen->font_set_num;
  1030. for( ; font_set_num-- ; font_set++) {
  1031. if(font_set->font_data) {
  1032. free_fontdataOC(dpy,
  1033. font_set->font_data, font_set->font_data_count);
  1034. Xfree(font_set->font_data);
  1035. font_set->font_data = NULL;
  1036. }
  1037. if(font_set->substitute) {
  1038. free_fontdataOC(dpy,
  1039. font_set->substitute, font_set->substitute_num);
  1040. Xfree(font_set->substitute);
  1041. font_set->substitute = NULL;
  1042. }
  1043. if(font_set->vmap) {
  1044. free_fontdataOC(dpy,
  1045. font_set->vmap, font_set->vmap_num);
  1046. Xfree(font_set->vmap);
  1047. font_set->vmap = NULL;
  1048. }
  1049. if(font_set->vrotate) {
  1050. free_fontdataOC(dpy,
  1051. (FontData)font_set->vrotate,
  1052. font_set->vrotate_num);
  1053. Xfree(font_set->vrotate);
  1054. font_set->vrotate = NULL;
  1055. }
  1056. }
  1057. Xfree(gen->font_set);
  1058. gen->font_set = NULL;
  1059. }
  1060. }
  1061. /* For VW/UDC end */
  1062. static void
  1063. destroy_oc(XOC oc)
  1064. {
  1065. Display *dpy = oc->core.om->core.display;
  1066. XOCGenericPart *gen = XOC_GENERIC(oc);
  1067. XFontStruct **font_list, *font;
  1068. FontSet font_set = (FontSet) NULL;
  1069. int font_set_num = 0;
  1070. int count = 0;
  1071. if (gen->mbs_to_cs)
  1072. _fallcCloseConverter(gen->mbs_to_cs);
  1073. if (gen->wcs_to_cs)
  1074. _fallcCloseConverter(gen->wcs_to_cs);
  1075. /* For VW/UDC start */ /* Change 1996.01.8 */
  1076. destroy_fontdata(gen,dpy);
  1077. /*
  1078. */
  1079. /* For VW/UDC end */
  1080. if (oc->core.base_name_list)
  1081. Xfree(oc->core.base_name_list);
  1082. if (oc->core.font_info.font_name_list)
  1083. falFreeStringList(oc->core.font_info.font_name_list);
  1084. if (font_list = oc->core.font_info.font_struct_list) {
  1085. Xfree(oc->core.font_info.font_struct_list);
  1086. }
  1087. if (oc->core.missing_list.charset_list)
  1088. falFreeStringList(oc->core.missing_list.charset_list);
  1089. Xfree(oc);
  1090. }
  1091. static char *
  1092. set_oc_values(XOC oc, XlcArgList args, int num_args)
  1093. {
  1094. if (oc->core.resources == NULL)
  1095. return NULL;
  1096. return _fallcSetValues((XPointer) oc, oc->core.resources,
  1097. oc->core.num_resources, args, num_args, XlcSetMask);
  1098. }
  1099. static char *
  1100. get_oc_values(XOC oc, XlcArgList args, int num_args)
  1101. {
  1102. if (oc->core.resources == NULL)
  1103. return NULL;
  1104. return _fallcGetValues((XPointer) oc, oc->core.resources,
  1105. oc->core.num_resources, args, num_args, XlcGetMask);
  1106. }
  1107. static XOCMethodsRec oc_default_methods = {
  1108. destroy_oc,
  1109. set_oc_values,
  1110. get_oc_values,
  1111. _falmbDefaultTextEscapement,
  1112. _falmbDefaultTextExtents,
  1113. _falmbDefaultTextPerCharExtents,
  1114. _falmbDefaultDrawString,
  1115. _falmbDefaultDrawImageString,
  1116. _falwcDefaultTextEscapement,
  1117. _falwcDefaultTextExtents,
  1118. _falwcDefaultTextPerCharExtents,
  1119. _falwcDefaultDrawString,
  1120. _falwcDefaultDrawImageString
  1121. };
  1122. static XOCMethodsRec oc_generic_methods = {
  1123. destroy_oc,
  1124. set_oc_values,
  1125. get_oc_values,
  1126. _falmbGenericTextEscapement,
  1127. _falmbGenericTextExtents,
  1128. _falmbGenericTextPerCharExtents,
  1129. _falmbGenericDrawString,
  1130. _falmbGenericDrawImageString,
  1131. _falwcGenericTextEscapement,
  1132. _falwcGenericTextExtents,
  1133. _falwcGenericTextPerCharExtents,
  1134. _falwcGenericDrawString,
  1135. _falwcGenericDrawImageString
  1136. };
  1137. typedef struct _XOCMethodsListRec {
  1138. char *name;
  1139. XOCMethods methods;
  1140. } XOCMethodsListRec, *XOCMethodsList;
  1141. static XOCMethodsListRec oc_methods_list[] = {
  1142. { "default", &oc_default_methods },
  1143. { "generic", &oc_generic_methods }
  1144. };
  1145. static XlcResource oc_resources[] = {
  1146. { XNBaseFontName, NULLQUARK, sizeof(char *),
  1147. XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
  1148. { XNOMAutomatic, NULLQUARK, sizeof(Bool),
  1149. XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
  1150. { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
  1151. XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
  1152. { XNDefaultString, NULLQUARK, sizeof(char *),
  1153. XOffsetOf(XOCRec, core.default_string), XlcGetMask },
  1154. { XNOrientation, NULLQUARK, sizeof(XOrientation),
  1155. XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
  1156. { XNResourceName, NULLQUARK, sizeof(char *),
  1157. XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
  1158. { XNResourceClass, NULLQUARK, sizeof(char *),
  1159. XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
  1160. { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
  1161. XOffsetOf(XOCRec, core.font_info), XlcGetMask }
  1162. };
  1163. static XOC
  1164. create_oc(XOM om, XlcArgList args, int num_args)
  1165. {
  1166. XOC oc;
  1167. XOMGenericPart *gen = XOM_GENERIC(om);
  1168. XOCMethodsList methods_list = oc_methods_list;
  1169. int count;
  1170. oc = (XOC) Xmalloc(sizeof(XOCGenericRec));
  1171. if (oc == NULL)
  1172. return (XOC) NULL;
  1173. bzero((char *) oc, sizeof(XOCGenericRec));
  1174. oc->core.om = om;
  1175. if (oc_resources[0].xrm_name == NULLQUARK)
  1176. _fallcCompileResourceList(oc_resources, XlcNumber(oc_resources));
  1177. if (_fallcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
  1178. args, num_args, XlcCreateMask | XlcDefaultMask)){
  1179. destroy_oc(oc);
  1180. return (XOC) NULL;
  1181. }
  1182. if (oc->core.base_name_list == NULL){
  1183. destroy_oc(oc);
  1184. return (XOC) NULL;
  1185. }
  1186. oc->core.resources = oc_resources;
  1187. oc->core.num_resources = XlcNumber(oc_resources);
  1188. if (create_fontset(oc) == False){
  1189. destroy_oc(oc);
  1190. return (XOC) NULL;
  1191. }
  1192. oc->methods = &oc_generic_methods;
  1193. if (gen->object_name) {
  1194. count = XlcNumber(oc_methods_list);
  1195. for ( ; count-- > 0; methods_list++) {
  1196. if (!_fallcCompareISOLatin1(gen->object_name, methods_list->name)) {
  1197. oc->methods = methods_list->methods;
  1198. break;
  1199. }
  1200. }
  1201. }
  1202. return oc;
  1203. }
  1204. static void
  1205. free_fontdataOM(FontData font_data, int font_data_count)
  1206. {
  1207. for( ; font_data_count-- ; font_data++) {
  1208. if(font_data->name){
  1209. Xfree(font_data->name);
  1210. font_data->name = NULL;
  1211. }
  1212. if(font_data->scopes){
  1213. Xfree(font_data->scopes);
  1214. font_data->scopes = NULL;
  1215. }
  1216. }
  1217. }
  1218. static Status
  1219. close_om(XOM om)
  1220. {
  1221. XOMGenericPart *gen = XOM_GENERIC(om);
  1222. OMData data;
  1223. int count;
  1224. if (data = gen->data) {
  1225. for (count = gen->data_num; count-- > 0; data++) {
  1226. if (data->charset_list){
  1227. Xfree(data->charset_list);
  1228. data->charset_list = NULL;
  1229. }
  1230. /* free font_data for om */
  1231. if (data->font_data) {
  1232. free_fontdataOM(data->font_data,data->font_data_count);
  1233. Xfree(data->font_data);
  1234. data->font_data = NULL;
  1235. }
  1236. /* free substitute for om */
  1237. if (data->substitute) {
  1238. free_fontdataOM(data->substitute,data->substitute_num);
  1239. Xfree(data->substitute);
  1240. data->substitute = NULL;
  1241. }
  1242. /* free vmap for om */
  1243. if (data->vmap) {
  1244. free_fontdataOM(data->vmap,data->vmap_num);
  1245. Xfree(data->vmap);
  1246. data->vmap = NULL;
  1247. }
  1248. /* free vrotate for om */
  1249. if (data->vrotate) {
  1250. #ifdef COMMENT
  1251. free_fontdataOM(data->vrotate,data->vrotate_num);
  1252. #endif /* COMMENT */
  1253. Xfree(data->vrotate);
  1254. data->vrotate = NULL;
  1255. }
  1256. }
  1257. Xfree(gen->data);
  1258. gen->data = NULL;
  1259. }
  1260. if (gen->object_name){
  1261. Xfree(gen->object_name);
  1262. gen->object_name = NULL;
  1263. }
  1264. if (om->core.res_name){
  1265. Xfree(om->core.res_name);
  1266. om->core.res_name = NULL;
  1267. }
  1268. if (om->core.res_class){
  1269. Xfree(om->core.res_class);
  1270. om->core.res_class = NULL;
  1271. }
  1272. if (om->core.required_charset.charset_list &&
  1273. om->core.required_charset.charset_count > 0){
  1274. falFreeStringList(om->core.required_charset.charset_list);
  1275. om->core.required_charset.charset_list = NULL;
  1276. } else {
  1277. Xfree((char*)om->core.required_charset.charset_list);
  1278. om->core.required_charset.charset_list = NULL;
  1279. }
  1280. if (om->core.orientation_list.orientation){
  1281. Xfree(om->core.orientation_list.orientation);
  1282. om->core.orientation_list.orientation = NULL;
  1283. }
  1284. Xfree(om);
  1285. return 0;
  1286. }
  1287. static char *
  1288. set_om_values(XOM om, XlcArgList args, int num_args)
  1289. {
  1290. if (om->core.resources == NULL)
  1291. return NULL;
  1292. return _fallcSetValues((XPointer) om, om->core.resources,
  1293. om->core.num_resources, args, num_args, XlcSetMask);
  1294. }
  1295. static char *
  1296. get_om_values(XOM om, XlcArgList args, int num_args)
  1297. {
  1298. if (om->core.resources == NULL)
  1299. return NULL;
  1300. return _fallcGetValues((XPointer) om, om->core.resources,
  1301. om->core.num_resources, args, num_args, XlcGetMask);
  1302. }
  1303. static XOMMethodsRec methods = {
  1304. close_om,
  1305. set_om_values,
  1306. get_om_values,
  1307. create_oc
  1308. };
  1309. static XlcResource om_resources[] = {
  1310. { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
  1311. XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
  1312. { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
  1313. XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
  1314. { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
  1315. XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
  1316. { XNContextualDrawing, NULLQUARK, sizeof(Bool),
  1317. XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
  1318. };
  1319. static XOM
  1320. create_om(
  1321. XLCd lcd,
  1322. Display *dpy,
  1323. XrmDatabase rdb,
  1324. char *res_name,
  1325. char *res_class)
  1326. {
  1327. XOM om;
  1328. om = (XOM) Xmalloc(sizeof(XOMGenericRec));
  1329. if (om == NULL)
  1330. return (XOM) NULL;
  1331. bzero((char *) om, sizeof(XOMGenericRec));
  1332. om->methods = &methods;
  1333. om->core.lcd = lcd;
  1334. om->core.display = dpy;
  1335. om->core.rdb = rdb;
  1336. if (res_name) {
  1337. om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1);
  1338. if (om->core.res_name == NULL){
  1339. close_om(om);
  1340. return (XOM) NULL;
  1341. }
  1342. strcpy(om->core.res_name, res_name);
  1343. }
  1344. if (res_class) {
  1345. om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1);
  1346. if (om->core.res_class == NULL){
  1347. close_om(om);
  1348. return (XOM) NULL;
  1349. }
  1350. strcpy(om->core.res_class, res_class);
  1351. }
  1352. if (om_resources[0].xrm_name == NULLQUARK)
  1353. _fallcCompileResourceList(om_resources, XlcNumber(om_resources));
  1354. om->core.resources = om_resources;
  1355. om->core.num_resources = XlcNumber(om_resources);
  1356. return om;
  1357. }
  1358. static OMData
  1359. add_data(XOM om)
  1360. {
  1361. XOMGenericPart *gen = XOM_GENERIC(om);
  1362. OMData new;
  1363. int num;
  1364. if (num = gen->data_num)
  1365. new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec));
  1366. else
  1367. new = (OMData) Xmalloc(sizeof(OMDataRec));
  1368. if (new == NULL)
  1369. return NULL;
  1370. gen->data_num = num + 1;
  1371. gen->data = new;
  1372. new += num;
  1373. bzero((char *) new, sizeof(OMDataRec));
  1374. return new;
  1375. }
  1376. /* For VW/UDC */
  1377. FontData
  1378. falread_EncodingInfo(int count, char **value)
  1379. {
  1380. FontData font_data,ret;
  1381. char *buf, *bufptr,*scp;
  1382. FontScope scope;
  1383. int len;
  1384. extern FontScope falparse_scopemaps();
  1385. font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count);
  1386. if (font_data == NULL)
  1387. return NULL;
  1388. bzero((char *) font_data, sizeof(FontDataRec) * count);
  1389. ret = font_data;
  1390. for ( ; count-- > 0; font_data++) {
  1391. /*
  1392. strcpy(buf, *value++);
  1393. */
  1394. buf = *value; value++;
  1395. if (bufptr = strchr(buf, ':')){
  1396. len = (int)(bufptr - buf);
  1397. bufptr++ ;
  1398. }
  1399. font_data->name = (char *) Xmalloc(len + 1);
  1400. if (font_data->name == NULL) {
  1401. XFree(font_data);
  1402. return NULL;
  1403. }
  1404. strncpy(font_data->name, buf,len);
  1405. font_data->name[len] = 0;
  1406. if (bufptr && _fallcCompareISOLatin1(bufptr, "GL") == 0)
  1407. font_data->side = XlcGL;
  1408. else if (bufptr && _fallcCompareISOLatin1(bufptr, "GR") == 0)
  1409. font_data->side = XlcGR;
  1410. else
  1411. font_data->side = XlcGLGR;
  1412. if (bufptr && (scp = strchr(bufptr, '['))){
  1413. font_data->scopes = falparse_scopemaps(scp,&(font_data->scopes_num));
  1414. }
  1415. }
  1416. return(ret);
  1417. }
  1418. static CodeRange read_vrotate(
  1419. int count,
  1420. char **value,
  1421. int *type,
  1422. int *vrotate_num)
  1423. {
  1424. FontData font_data,ret;
  1425. char *buf, *bufptr,*scp;
  1426. CodeRange range;
  1427. extern FontScope falparse_scopemaps();
  1428. if(!strcmp(value[0],"all")){
  1429. *type = VROTATE_ALL ;
  1430. *vrotate_num = 0 ;
  1431. return (NULL);
  1432. } else if(*(value[0]) == '['){
  1433. *type = VROTATE_PART ;
  1434. range = (CodeRange)falparse_scopemaps(value[0],vrotate_num);
  1435. return (range);
  1436. } else {
  1437. *type = VROTATE_NONE ;
  1438. *vrotate_num = 0 ;
  1439. return (NULL);
  1440. }
  1441. }
  1442. static void
  1443. read_vw(XLCd lcd, OMData font_set, int num)
  1444. {
  1445. char **value, buf[BUFSIZ], *bufptr;
  1446. int count,i;
  1447. snprintf(buf, sizeof(buf), "fs%d.font.vertical_map", num);
  1448. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1449. if (count > 0){
  1450. dbg_printValue(buf,value,count);
  1451. font_set->vmap_num = count;
  1452. font_set->vmap = falread_EncodingInfo(count,value);
  1453. }
  1454. snprintf(buf, sizeof(buf), "fs%d.font.vertical_rotate", num);
  1455. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1456. if (count > 0){
  1457. dbg_printValue(buf,value,count);
  1458. font_set->vrotate = read_vrotate(count,value,&(font_set->vrotate_type),
  1459. &(font_set->vrotate_num));
  1460. }
  1461. }
  1462. /* VW/UDC end */
  1463. static Bool
  1464. init_om(XOM om)
  1465. {
  1466. XLCd lcd = om->core.lcd;
  1467. XOMGenericPart *gen = XOM_GENERIC(om);
  1468. OMData data;
  1469. XlcCharSet *charset_list;
  1470. FontData font_data;
  1471. char **required_list;
  1472. XOrientation *orientation;
  1473. char **value, buf[BUFSIZ], *bufptr;
  1474. int count = 0, num = 0, length = 0;
  1475. _fallcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count);
  1476. if (count > 0 && _fallcCompareISOLatin1(*value, "True") == 0)
  1477. gen->on_demand_loading = True;
  1478. _fallcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
  1479. if (count > 0) {
  1480. gen->object_name = (char *) Xmalloc(strlen(*value) + 1);
  1481. if (gen->object_name == NULL)
  1482. return False;
  1483. strcpy(gen->object_name, *value);
  1484. }
  1485. for (num = 0; ; num++) {
  1486. snprintf(buf, sizeof(buf), "fs%d.charset.name", num);
  1487. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1488. if( count < 1){
  1489. snprintf(buf, sizeof(buf), "fs%d.charset", num);
  1490. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1491. if (count < 1)
  1492. break;
  1493. }
  1494. data = add_data(om);
  1495. if (data == NULL)
  1496. return False;
  1497. charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count);
  1498. if (charset_list == NULL)
  1499. return False;
  1500. data->charset_list = charset_list;
  1501. data->charset_count = count;
  1502. while (count-- > 0){
  1503. *charset_list++ = _fallcGetCharSet(*value++);
  1504. }
  1505. snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", num);
  1506. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1507. if( count > 0){
  1508. UDCArea udc;
  1509. int i,flag = 0;
  1510. udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec));
  1511. if (udc == NULL)
  1512. return False;
  1513. for(i=0;i<count;i++){
  1514. sscanf(value[i],"\\x%lx,\\x%lx", &(udc[i].start), &(udc[i].end));
  1515. }
  1516. for(i=0;i<data->charset_count;i++){
  1517. if(data->charset_list[i]->udc_area == NULL){
  1518. data->charset_list[i]->udc_area = udc;
  1519. data->charset_list[i]->udc_area_num = count;
  1520. flag = 1;
  1521. }
  1522. }
  1523. if(flag == 0){
  1524. Xfree(udc);
  1525. }
  1526. }
  1527. snprintf(buf, sizeof(buf), "fs%d.font.primary", num);
  1528. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1529. if (count < 1){
  1530. snprintf(buf, sizeof(buf), "fs%d.font", num);
  1531. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1532. if (count < 1)
  1533. return False;
  1534. }
  1535. font_data = falread_EncodingInfo(count,value);
  1536. if (font_data == NULL)
  1537. return False;
  1538. data->font_data = font_data;
  1539. data->font_data_count = count;
  1540. snprintf(buf, sizeof(buf), "fs%d.font.substitute", num);
  1541. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1542. if (count > 0){
  1543. font_data = falread_EncodingInfo(count,value);
  1544. if (font_data == NULL)
  1545. return False;
  1546. data->substitute = font_data;
  1547. data->substitute_num = count;
  1548. } else {
  1549. snprintf(buf, sizeof(buf), "fs%d.font", num);
  1550. _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
  1551. if (count < 1) {
  1552. data->substitute = NULL;
  1553. data->substitute_num = 0;
  1554. } else {
  1555. font_data = falread_EncodingInfo(count,value);
  1556. data->substitute = font_data;
  1557. data->substitute_num = count;
  1558. }
  1559. }
  1560. read_vw(lcd,data,num);
  1561. length += strlen(data->font_data->name) + 1;
  1562. }
  1563. /* required charset list */
  1564. required_list = (char **) Xmalloc(sizeof(char *) * gen->data_num);
  1565. if (required_list == NULL)
  1566. return False;
  1567. bufptr = (char *) Xmalloc(length);
  1568. if (bufptr == NULL) {
  1569. Xfree(required_list);
  1570. return False;
  1571. }
  1572. om->core.required_charset.charset_list = required_list;
  1573. om->core.required_charset.charset_count = gen->data_num;
  1574. count = gen->data_num;
  1575. data = gen->data;
  1576. for ( ; count-- > 0; data++) {
  1577. strcpy(bufptr, data->font_data->name);
  1578. *required_list++ = bufptr;
  1579. bufptr += strlen(bufptr) + 1;
  1580. }
  1581. /* orientation list */
  1582. orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2);
  1583. if (orientation == NULL)
  1584. return False;
  1585. orientation[0] = XOMOrientation_LTR_TTB;
  1586. orientation[1] = XOMOrientation_TTB_RTL;
  1587. om->core.orientation_list.orientation = orientation;
  1588. om->core.orientation_list.num_orientation = 2;
  1589. /* directional dependent drawing */
  1590. om->core.directional_dependent = False;
  1591. /* contexual drawing */
  1592. om->core.contextual_drawing = False;
  1593. /* context dependent */
  1594. om->core.context_dependent = False;
  1595. return True;
  1596. }
  1597. XOM
  1598. _falomGenericOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
  1599. char *res_name, char *res_class)
  1600. {
  1601. XOM om;
  1602. om = create_om(lcd, dpy, rdb, res_name, res_class);
  1603. if (om == NULL)
  1604. return (XOM) NULL;
  1605. if (init_om(om) == False){
  1606. close_om(om);
  1607. return (XOM) NULL;
  1608. }
  1609. return om;
  1610. }
  1611. Bool
  1612. _falInitOM(XLCd lcd)
  1613. {
  1614. lcd->methods->open_om = _falomGenericOpenOM;
  1615. return True;
  1616. }