12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880 |
- /*
- * CDE - Common Desktop Environment
- *
- * Copyright (c) 1993-2012, The Open Group. All rights reserved.
- *
- * These libraries and programs are free software; you can
- * redistribute them and/or modify them under the terms of the GNU
- * Lesser General Public License as published by the Free Software
- * Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * These libraries and programs are distributed in the hope that
- * they will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
- * PURPOSE. See the GNU Lesser General Public License for more
- * details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with these libraries and programs; if not, write
- * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
- * Floor, Boston, MA 02110-1301 USA
- */
- /* omGeneric.c 1.9 - Fujitsu source for CDEnext 96/04/26 11:20:11 */
- /* $XConsortium: _falomGeneric.c /main/4 1996/09/27 19:03:50 drk $ */
- /*
- * Copyright 1992, 1993 by TOSHIBA Corp.
- *
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of TOSHIBA not be used in advertising
- * or publicity pertaining to distribution of the software without specific,
- * written prior permission. TOSHIBA make no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
- * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
- * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
- * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
- * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
- * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
- * SOFTWARE.
- *
- * Author: Katsuhisa Yano TOSHIBA Corp.
- * mopi@osa.ilab.toshiba.co.jp
- */
- /*
- * Copyright 1995 by FUJITSU LIMITED
- * This is source code modified by FUJITSU LIMITED under the Joint
- * Development Agreement for the CDEnext PST.
- * This is unpublished proprietary source code of FUJITSU LIMITED
- *
- * Modifier: Takanori Tateno FUJITSU LIMITED
- *
- */
- #include "_fallibint.h"
- #include "_falomGeneric.h"
- #include <X11/Xos.h>
- #include <X11/Xatom.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- #define MAXFONTS 100
- #define PIXEL_SIZE_FIELD 7
- #define POINT_SIZE_FIELD 8
- #define CHARSET_ENCODING_FIELD 14
- extern int _falmbDefaultTextEscapement(), _falwcDefaultTextEscapement();
- extern int _falmbDefaultTextExtents(), _falwcDefaultTextExtents();
- extern Status _falmbDefaultTextPerCharExtents(), _falwcDefaultTextPerCharExtents();
- extern int _falmbDefaultDrawString(), _falwcDefaultDrawString();
- extern void _falmbDefaultDrawImageString(), _falwcDefaultDrawImageString();
- extern int _falmbGenericTextEscapement(), _falwcGenericTextEscapement();
- extern int _falmbGenericTextExtents(), _falwcGenericTextExtents();
- extern Status _falmbGenericTextPerCharExtents(), _falwcGenericTextPerCharExtents();
- extern int _falmbGenericDrawString(), _falwcGenericDrawString();
- extern void _falmbGenericDrawImageString(), _falwcGenericDrawImageString();
- extern void dbg_printValue(char *str, char **value, int num);
- /* For VW/UDC start */
- static FontData
- init_fontdata(FontData font_data, int font_data_count)
- {
- FontData fd;
- int i;
- fd = (FontData)Xmalloc(sizeof(FontDataRec) * font_data_count);
- if(fd == (FontData) NULL)
- return False;
- memset(fd, 0x00, sizeof(FontData) * font_data_count);
- for(i = 0 ; i < font_data_count ; i++)
- fd[i] = font_data[i];
- return fd;
- }
- static VRotate
- init_vrotate(
- FontData font_data,
- int font_data_count,
- int type,
- CodeRange code_range,
- int code_range_num)
- {
- VRotate vrotate;
- int i;
- if(type == VROTATE_NONE)
- return (VRotate)NULL;
- vrotate = (VRotate)Xmalloc(sizeof(VRotateRec) * font_data_count);
- if(vrotate == (VRotate) NULL)
- return False;
- memset(vrotate, 0x00, sizeof(VRotateRec) * font_data_count);
- for(i = 0 ; i < font_data_count ; i++) {
- vrotate[i].charset_name = font_data[i].name;
- vrotate[i].side = font_data[i].side;
- if(type == VROTATE_PART) {
- vrotate[i].num_cr = code_range_num;
- vrotate[i].code_range = code_range;
- }
- }
- return vrotate;
- }
- static Bool
- init_fontset(XOC oc)
- {
- XOCGenericPart *gen;
- FontSet font_set;
- OMData data;
- int count;
- int err = 0;
- count = XOM_GENERIC(oc->core.om)->data_num;
- data = XOM_GENERIC(oc->core.om)->data;
- font_set = (FontSet) Xmalloc(sizeof(FontSetRec) * count);
- if (font_set == NULL)
- return False;
- memset((char *) font_set, 0x00, sizeof(FontSetRec) * count);
- gen = XOC_GENERIC(oc);
- gen->font_set_num = count;
- gen->font_set = font_set;
- for ( ; count-- > 0; data++, font_set++) {
- font_set->charset_count = data->charset_count;
- font_set->charset_list = data->charset_list;
- if((font_set->font_data = init_fontdata(data->font_data,
- data->font_data_count)) == NULL){
- err += 1;
- break;
- }
- font_set->font_data_count = data->font_data_count;
- if((font_set->substitute = init_fontdata(data->substitute,
- data->substitute_num)) == NULL){
- err += 1;
- break;
- }
- font_set->substitute_num = data->substitute_num;
- if((font_set->vmap = init_fontdata(data->vmap,
- data->vmap_num)) == NULL){
- err += 1;
- break;
- }
- font_set->vmap_num = data->vmap_num;
- if(data->vrotate_type != VROTATE_NONE) {
- /* A vrotate member is specified primary font data */
- /* as initial value. */
- if((font_set->vrotate = init_vrotate(data->font_data,
- data->font_data_count,
- data->vrotate_type,
- data->vrotate,
- data->vrotate_num)) == NULL){
- err += 1;
- break;
- }
- font_set->vrotate_num = data->font_data_count;
- }
- }
- if (err == 1){
- if(font_set->font_data)
- Xfree(font_set->font_data);
- if(font_set->substitute)
- Xfree(font_set->substitute);
- if(font_set->vmap)
- Xfree(font_set->vmap);
- if(font_set->vrotate)
- Xfree(font_set->vrotate);
- if(font_set)
- Xfree(font_set);
- gen->font_set = (FontSet) NULL;
- gen->font_set_num = 0;
- return False;
- } else {
- return True;
- }
- }
- /* For VW/UDC end */
- static char *
- get_prop_name(Display *dpy, XFontStruct *fs)
- {
- unsigned long fp;
- if (falGetFontProperty(fs, XA_FONT, &fp))
- return falGetAtomName(dpy, fp);
- return (char *) NULL;
- }
- static FontData
- check_charset(FontSet font_set, char *font_name)
- {
- FontData font_data;
- char *last;
- int count, length, name_len;
- name_len = strlen(font_name);
- last = font_name + name_len;
- count = font_set->font_data_count;
- font_data = font_set->font_data;
- for ( ; count-- > 0; font_data++) {
- length = strlen(font_data->name);
- if (length > name_len)
- continue;
- if (_fallcCompareISOLatin1(last - length, font_data->name) == 0)
- return font_data;
- }
- return (FontData) NULL;
- }
- static int
- check_fontname(XOC oc, char *name, int found_num)
- {
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontData data;
- FontSet font_set;
- XFontStruct *fs_list;
- char **fn_list, *fname, *prop_fname = NULL;
- int list_num, font_set_num, i;
- int list2_num;
- char **fn2_list = NULL;
- fn_list = falListFonts(dpy, name, MAXFONTS, &list_num);
- if (fn_list == NULL)
- return found_num;
- for (i = 0; i < list_num; i++) {
- fname = fn_list[i];
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->font_name)
- continue;
- if ((data = check_charset(font_set, fname)) == NULL) {
- if ((fn2_list = falListFontsWithInfo(dpy, name, MAXFONTS,
- &list2_num, &fs_list))
- && (prop_fname = get_prop_name(dpy, fs_list))
- && (data = check_charset(font_set, prop_fname)))
- fname = prop_fname;
- }
- if (data) {
- font_set->side = data->side;
- font_set->font_name = (char *) Xmalloc(strlen(fname) + 1);
- if (font_set->font_name) {
- strcpy(font_set->font_name, fname);
- found_num++;
- }
- }
- if (fn2_list) {
- falFreeFontInfo(fn2_list, fs_list, list2_num);
- fn2_list = NULL;
- if (prop_fname) {
- Xfree(prop_fname);
- prop_fname = NULL;
- }
- }
- if (found_num == gen->font_set_num)
- break;
- }
- }
- falFreeFontNames(fn_list);
- return found_num;
- }
- /* For VW/UDC start */
- static Bool
- load_fontdata(XOC oc, FontData font_data, int font_data_num)
- {
- Display *dpy = oc->core.om->core.display;
- FontData fd = font_data;
- for( ; font_data_num-- ; fd++) {
- if(fd->xlfd_name != (char *) NULL && fd->font == NULL) {
- fd->font = falLoadQueryFont(dpy, fd->xlfd_name);
- if (fd->font == NULL)
- return False;
- }
- }
- return True;
- }
- static Bool
- load_font(XOC oc)
- {
- int i;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- int num = gen->font_set_num;
- for ( ; num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
- if(load_fontdata(oc, font_set->font_data,
- font_set->font_data_count) != True)
- return False;
- if(load_fontdata(oc, font_set->substitute,
- font_set->substitute_num) != True)
- return False;
- if(font_set->font_data_count > 0 && font_set->font_data->font) {
- font_set->font = font_set->font_data->font;
- } else if(font_set->substitute_num > 0 ) {
- for(i=0;i<font_set->substitute_num;i++){
- if(font_set->substitute[i].font != NULL){
- font_set->font = font_set->substitute[i].font;
- }
- }
- }
- load_fontdata(oc, font_set->vmap, font_set->vmap_num);
- load_fontdata(oc, (FontData) font_set->vrotate,
- font_set->vrotate_num);
- if (font_set->font->min_byte1 || font_set->font->max_byte1)
- font_set->is_xchar2b = True;
- else
- font_set->is_xchar2b = False;
- }
- return True;
- }
- /* For VW/UDC end */
- static Bool
- load_font_info(XOC oc)
- {
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- char **fn_list;
- int fn_num, num = gen->font_set_num;
- for ( ; num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
- if (font_set->info == NULL) {
- fn_list = falListFontsWithInfo(dpy, font_set->font_name, 1, &fn_num,
- &font_set->info);
- if (font_set->info == NULL)
- return False;
- falFreeFontNames(fn_list);
- }
- }
- return True;
- }
- /* For Vertical Writing start */
- static void
- check_fontset_extents(
- XCharStruct *overall,
- int *logical_ascent,
- int *logical_descent,
- XFontStruct *font)
- {
- overall->lbearing = min(overall->lbearing, font->min_bounds.lbearing);
- overall->rbearing = max(overall->rbearing, font->max_bounds.rbearing);
- overall->ascent = max(overall->ascent, font->max_bounds.ascent);
- overall->descent = max(overall->descent, font->max_bounds.descent);
- overall->width = max(overall->width, font->max_bounds.width);
- *logical_ascent = max(*logical_ascent, font->ascent);
- *logical_descent = max(*logical_descent, font->descent);
- }
- /* For Vertical Writing end */
- static void
- set_fontset_extents(XOC oc)
- {
- XRectangle *ink = &oc->core.font_set_extents.max_ink_extent;
- XRectangle *logical = &oc->core.font_set_extents.max_logical_extent;
- XFontStruct **font_list, *font;
- XCharStruct overall;
- int logical_ascent, logical_descent;
- int num = oc->core.font_info.num_font;
- font_list = oc->core.font_info.font_struct_list;
- font = *font_list++;
- overall = font->max_bounds;
- overall.lbearing = font->min_bounds.lbearing;
- logical_ascent = font->ascent;
- logical_descent = font->descent;
- /* For Vertical Writing start */
- while (--num > 0) {
- font = *font_list++;
- check_fontset_extents(&overall, &logical_ascent, &logical_descent,
- font);
- }
- {
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set = gen->font_set;
- FontData font_data;
- int font_set_num = gen->font_set_num;
- int font_data_count;
- for( ; font_set_num-- ; font_set++) {
- if(font_set->vmap_num > 0) {
- font_data = font_set->vmap;
- font_data_count = font_set->vmap_num;
- for( ; font_data_count-- ; font_data++) {
- if(font_data->font != NULL) {
- check_fontset_extents(&overall, &logical_ascent,
- &logical_descent,
- font_data->font);
- }
- }
- }
- #ifndef COMMENT
- if(font_set->vrotate_num > 0) {
- font_data = (FontData) font_set->vrotate;
- font_data_count = font_set->vrotate_num;
- for( ; font_data_count-- ; font_data++) {
- if(font_data->font != NULL) {
- check_fontset_extents(&overall, &logical_ascent,
- &logical_descent,
- font_data->font);
- }
- }
- }
- #endif /* COMMENT */
- }
- }
- /* For Vertical Writing start */
- ink->x = overall.lbearing;
- ink->y = -(overall.ascent);
- ink->width = overall.rbearing - overall.lbearing;
- ink->height = overall.ascent + overall.descent;
- logical->x = 0;
- logical->y = -(logical_ascent);
- logical->width = overall.width;
- logical->height = logical_ascent + logical_descent;
- }
- static Bool
- init_core_part(XOC oc)
- {
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- int font_set_num;
- XFontStruct **font_struct_list;
- char **font_name_list, *font_name_buf;
- int count, length;
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- count = length = 0;
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->font_name == NULL)
- continue;
- length += strlen(font_set->font_name) + 1;
- count++;
- }
- if (count == 0)
- return False;
- font_struct_list = (XFontStruct **) Xmalloc(sizeof(XFontStruct *) * count);
- if (font_struct_list == NULL)
- return False;
- font_name_list = (char **) Xmalloc(sizeof(char *) * count);
- if (font_name_list == NULL){
- if (font_name_list)
- Xfree(font_name_list);
- Xfree(font_struct_list);
- return False;
- }
- font_name_buf = (char *) Xmalloc(length);
- if (font_name_buf == NULL){
- if (font_name_list)
- Xfree(font_name_list);
- Xfree(font_struct_list);
- return False;
- }
- oc->core.font_info.num_font = count;
- oc->core.font_info.font_name_list = font_name_list;
- oc->core.font_info.font_struct_list = font_struct_list;
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for (count = 0; font_set_num-- > 0; font_set++, count++) {
- if (font_set->font_name == NULL)
- continue;
- font_set->id = count;
- if (font_set->font)
- *font_struct_list++ = font_set->font;
- else
- *font_struct_list++ = font_set->info;
- strcpy(font_name_buf, font_set->font_name);
- Xfree(font_set->font_name);
- *font_name_list++ = font_set->font_name = font_name_buf;
- font_name_buf += strlen(font_name_buf) + 1;
- }
- set_fontset_extents(oc);
- return True;
- }
- static char *
- get_font_name(XOC oc, char *pattern)
- {
- char **list, *name;
- int count = 0;
- list = falListFonts(oc->core.om->core.display, pattern, 1, &count);
- if (list == NULL)
- return NULL;
- name = (char *) Xmalloc(strlen(*list) + 1);
- if (name)
- strcpy(name, *list);
- falFreeFontNames(list);
- return name;
- }
- /* For VW/UDC start*/
- static char
- *get_rotate_fontname(char *font_name)
- {
- char *pattern = NULL, *ptr = NULL;
- char *fields[CHARSET_ENCODING_FIELD];
- char str_pixel[32], str_point[4];
- char rotate_font[256];
- char *rotate_font_ptr = NULL;
- int pixel_size = 0;
- int field_num = 0, len = 0;
- if(font_name == (char *) NULL || (len = strlen(font_name)) <= 0)
- return NULL;
- pattern = (char *)Xmalloc(len + 1);
- if(!pattern)
- return NULL;
- strcpy(pattern, font_name);
- memset(fields, 0, sizeof(char *) * 14);
- ptr = pattern;
- while(isspace(*ptr)) {
- ptr++;
- }
- if(*ptr == '-')
- ptr++;
- for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD && ptr && *ptr ;
- ptr++, field_num++) {
- fields[field_num] = ptr;
- if(ptr = strchr(ptr, '-')) {
- *ptr = '\0';
- }
- }
- if(field_num < CHARSET_ENCODING_FIELD) {
- Xfree(pattern);
- return NULL;
- }
- /* Pixel Size field : fields[6] */
- for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) {
- if(!isdigit(*ptr)) {
- Xfree(pattern);
- return NULL;
- }
- }
- pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]);
- snprintf(str_pixel, sizeof(str_pixel), "[ 0 ~%d %d 0 ]", pixel_size, pixel_size);
- fields[6] = str_pixel;
- /* Point Size field : fields[7] */
- strcpy(str_point, "*");
- fields[POINT_SIZE_FIELD - 1] = str_point;
- rotate_font[0] = '\0';
- for(field_num = 0 ; field_num < CHARSET_ENCODING_FIELD &&
- fields[field_num] ; field_num++) {
- snprintf(rotate_font, sizeof(rotate_font), "%s-%s", rotate_font, fields[field_num]);
- }
- if(pattern)
- Xfree(pattern);
- rotate_font_ptr = (char *)Xmalloc(strlen(rotate_font) + 1);
- if(!rotate_font_ptr)
- return NULL;
- strcpy(rotate_font_ptr, rotate_font);
- return rotate_font_ptr;
- }
- static Bool
- is_match_charset(FontData font_data, char *font_name)
- {
- char *last;
- int length, name_len;
- name_len = strlen(font_name);
- last = font_name + name_len;
- length = strlen(font_data->name);
- if (length > name_len)
- return False;
- if (_fallcCompareISOLatin1(last - length, font_data->name) == 0)
- return True;
- return False;
- }
- static int
- parse_all_name(XOC oc, FontData font_data, char *pattern)
- {
- if(is_match_charset(font_data, pattern) != True)
- return False;
- font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
- if(font_data->xlfd_name == NULL)
- return (-1);
- strcpy(font_data->xlfd_name, pattern);
- return True;
- }
- static int
- parse_omit_name(XOC oc, FontData font_data, char *pattern)
- {
- char *font_name = (char *) NULL;
- char *last = (char *) NULL;
- char buf[BUFSIZE];
- int length = 0;
- if(is_match_charset(font_data, pattern) == True) {
- strcpy(buf, pattern);
- if (font_name = get_font_name(oc, buf)) {
- font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
- if(font_data->xlfd_name == NULL) {
- Xfree(font_name);
- return (-1);
- }
- strcpy(font_data->xlfd_name, font_name);
- Xfree(font_name);
- return True;
- }
- }
- snprintf(buf, sizeof(buf), "%s", pattern);
- length = strlen(pattern);
- last = buf + length - 1;
- if (length > 1 && *last == '*' && *(last - 1) == '-') {
- if (length > 3 && *(last - 2) == '*' && *(last - 3) == '-')
- last -= 2;
- } else {
- ++last;
- *last++ = '-';
- }
- strcpy(last, font_data->name);
- if (font_name = get_font_name(oc, buf)) {
- font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
- if(font_data->xlfd_name == NULL) {
- Xfree(font_name);
- return (-1);
- }
- strcpy(font_data->xlfd_name, font_name);
- Xfree(font_name);
- return True;
- }
- *last = '*';
- *(last + 1) = '-';
- strcpy(last + 2, font_data->name);
- if (font_name = get_font_name(oc, buf)) {
- font_data->xlfd_name = (char *)Xmalloc(strlen(font_name) + 1);
- if(font_data->xlfd_name == NULL) {
- Xfree(font_name);
- return (-1);
- }
- strcpy(font_data->xlfd_name, font_name);
- Xfree(font_name);
- return True;
- }
- return False;
- }
- typedef enum{C_PRIMARY, C_SUBSTITUTE, C_VMAP, C_VROTATE } ClassType;
- static int
- parse_fontdata(
- XOC oc,
- FontData font_data,
- int font_data_count,
- char **name_list,
- int name_list_count,
- ClassType class)
- {
- char **cur_name_list = name_list;
- char *font_name = (char *) NULL;
- char *pattern = (char *) NULL;
- int found_num = 0, ret = 0;
- int fd_count = font_data_count;
- int count = name_list_count;
- Bool is_found = False;
- if(name_list == NULL || count <= 0) {
- return False;
- }
- if(font_data == NULL || font_data_count <= 0) {
- return False;
- }
- for ( ; font_data_count-- > 0; font_data++) {
- is_found = False;
- font_name = (char *) NULL;
- count = name_list_count;
- cur_name_list = name_list;
- while (count-- > 0) {
- pattern = *cur_name_list++;
- if (pattern == NULL || *pattern == '\0')
- continue;
- /* When the font name is specified a full name. */
- if (strchr(pattern, '*') == NULL &&
- (font_name = get_font_name(oc, pattern))) {
- ret = parse_all_name(oc, font_data, font_name);
- Xfree(font_name);
- if(ret == -1)
- return ret;
- else if (ret == True) {
- found_num++;
- is_found = True;
- break;
- } else
- continue;
- }
- /* When the font name is specified a omited name. */
- ret = parse_omit_name(oc, font_data, pattern);
- if(ret == -1)
- return ret;
- else if (ret == True) {
- found_num++;
- is_found = True;
- break;
- } else
- continue;
- }
- switch(class) {
- case C_PRIMARY:
- if(is_found != True)
- return False;
- break;
- case C_SUBSTITUTE:
- case C_VMAP:
- if(is_found == True)
- return True;
- break;
- case C_VROTATE:
- if(is_found == True) {
- char *rotate_name;
- if((rotate_name = get_rotate_fontname(font_data->xlfd_name)) !=
- NULL) {
- Xfree(font_data->xlfd_name);
- font_data->xlfd_name = rotate_name;
- return True;
- }
- Xfree(font_data->xlfd_name);
- return False;
- }
- }
- }
- if(class == C_PRIMARY && found_num == fd_count)
- return True;
- return False;
- }
- static int
- parse_vw(XOC oc, FontSet font_set, char **name_list, int count)
- {
- FontData vmap = font_set->vmap;
- VRotate vrotate = font_set->vrotate;
- int vmap_num = font_set->vmap_num;
- int vrotate_num = font_set->vrotate_num;
- int ret = 0, i = 0;
- if(vmap_num > 0) {
- if(parse_fontdata(oc, vmap, vmap_num, name_list, count, C_VMAP) == -1)
- return (-1);
- }
- if(vrotate_num > 0) {
- ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num,
- name_list, count, C_VROTATE);
- if(ret == -1) {
- return (-1);
- } else if(ret == False) {
- CodeRange code_range;
- int num_cr;
- int sub_num = font_set->substitute_num;
- code_range = vrotate[i].code_range;
- num_cr = vrotate[i].num_cr;
- for(i = 0 ; i < vrotate_num ; i++) {
- if(vrotate[i].xlfd_name)
- Xfree(vrotate[i].xlfd_name);
- }
- Xfree(vrotate);
- if(sub_num > 0) {
- vrotate = font_set->vrotate = (VRotate)Xmalloc
- (sizeof(VRotateRec) * sub_num);
- if(font_set->vrotate == (VRotate)NULL)
- return (-1);
- for(i = 0 ; i < sub_num ; i++) {
- vrotate[i].charset_name = font_set->substitute[i].name;
- vrotate[i].side = font_set->substitute[i].side;
- vrotate[i].code_range = code_range;
- vrotate[i].num_cr = num_cr;
- }
- vrotate_num = font_set->vrotate_num = sub_num;
- } else {
- font_set->vrotate = (VRotate)NULL;
- }
- ret = parse_fontdata(oc, (FontData) vrotate, vrotate_num,
- name_list, count, C_VROTATE);
- if(ret == -1)
- return (-1);
- }
- }
- return True;
- }
- static int
- parse_fontname(XOC oc)
- {
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- char *base_name, **name_list;
- int font_set_num = 0;
- int found_num = 0;
- int count = 0;
- int ret;
- int i;
- name_list = _falParseBaseFontNameList(oc->core.base_name_list, &count);
- if (name_list == NULL)
- return -1;
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for( ; font_set_num-- > 0 ; font_set++) {
- if(font_set->font_name)
- continue;
- if(font_set->font_data_count > 0) {
- ret = parse_fontdata(oc, font_set->font_data,
- font_set->font_data_count,
- name_list, count, C_PRIMARY);
- if(ret == -1) {
- falFreeStringList(name_list);
- return -1;
- } else if(ret == True) {
- font_set->font_name = (char *)Xmalloc
- (strlen(font_set->font_data->xlfd_name) + 1);
- if(font_set->font_name == (char *) NULL){
- falFreeStringList(name_list);
- return -1;
- }
- strcpy(font_set->font_name, font_set->font_data->xlfd_name);
- font_set->side = font_set->font_data->side;
- if(parse_vw(oc, font_set, name_list, count) == -1){
- falFreeStringList(name_list);
- return -1;
- }
- found_num++;
- /* The substitute font is serched, when the primary fonts */
- /* is not found. */
- } else {
- /* The primary information is free from FontSet structure */
- font_set->font_data_count = 0;
- if(font_set->font_data) {
- Xfree(font_set->font_data);
- font_set->font_data = (FontData) NULL;
- }
- /* A vrotate member is replaced to substitute information */
- /* from primary information. */
- font_set->vrotate_num = 0;
- if(font_set->vrotate) {
- Xfree(font_set->vrotate);
- font_set->vrotate = (VRotate) NULL;
- }
- ret = parse_fontdata(oc, font_set->substitute,
- font_set->substitute_num,
- name_list, count, C_SUBSTITUTE);
- if(ret == -1) {
- falFreeStringList(name_list);
- return -1;
- } else if(ret == True) {
- for(i=0;i<font_set->substitute_num;i++){
- if(font_set->substitute[i].xlfd_name != NULL){
- break;
- }
- }
- font_set->font_name = (char *)Xmalloc
- (strlen(font_set->substitute[i].xlfd_name) + 1);
- if(font_set->font_name == (char *) NULL){
- falFreeStringList(name_list);
- return -1;
- }
- strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
- font_set->side = font_set->substitute[i].side;
- if(parse_vw(oc, font_set, name_list, count) == -1){
- falFreeStringList(name_list);
- return -1;
- }
- found_num++;
- }
- }
- } else if(font_set->substitute_num > 0) {
- ret = parse_fontdata(oc, font_set->substitute,
- font_set->substitute_num,
- name_list, count, C_SUBSTITUTE);
- if(ret == -1) {
- falFreeStringList(name_list);
- return -1;
- } else if(ret == True) {
- for(i=0;i<font_set->substitute_num;i++){
- if(font_set->substitute[i].xlfd_name != NULL){
- break;
- }
- }
- font_set->font_name = (char *)Xmalloc
- (strlen(font_set->substitute[i].xlfd_name) + 1);
- if(font_set->font_name == (char *) NULL){
- falFreeStringList(name_list);
- return -1;
- }
- strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
- font_set->side = font_set->substitute[i].side;
- if(parse_vw(oc, font_set, name_list, count) == -1){
- falFreeStringList(name_list);
- return -1;
- }
- found_num++;
- }
- }
- }
- base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
- if (base_name == NULL){
- falFreeStringList(name_list);
- return -1;
- }
- strcpy(base_name, oc->core.base_name_list);
- oc->core.base_name_list = base_name;
- falFreeStringList(name_list);
- return found_num;
- }
- /* For VW/UDC end*/
- static Bool
- set_missing_list(XOC oc)
- {
- XOCGenericPart *gen = XOC_GENERIC(oc);
- FontSet font_set;
- char **charset_list, *charset_buf;
- int count, length, font_set_num;
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- count = length = 0;
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->info || font_set->font)
- continue;
- /* Change 1996.01.23 start */
- if(font_set->font_data_count <= 0 ||
- font_set->font_data == (FontData)NULL) {
- if(font_set->substitute_num <= 0 ||
- font_set->substitute == (FontData)NULL)
- if(font_set->charset_list != NULL){
- length +=
- strlen(font_set->charset_list[0]->encoding_name) + 1;
- } else {
- length += 1;
- }
- else
- length += strlen(font_set->substitute->name) + 1;
- } else {
- length += strlen(font_set->font_data->name) + 1;
- }
- /* Change 1996.01.23 end */
- count++;
- }
- if (count < 1)
- return True;
- charset_list = (char **) Xmalloc(sizeof(char *) * count);
- if (charset_list == NULL)
- return False;
- charset_buf = (char *) Xmalloc(length);
- if (charset_buf == NULL) {
- Xfree(charset_list);
- return False;
- }
- oc->core.missing_list.charset_list = charset_list;
- oc->core.missing_list.charset_count = count;
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for ( ; font_set_num-- > 0; font_set++) {
- if (font_set->info || font_set->font)
- continue;
- /* Change 1996.01.23 start */
- if(font_set->font_data_count <= 0 ||
- font_set->font_data == (FontData)NULL) {
- if(font_set->substitute_num <= 0 ||
- font_set->substitute == (FontData)NULL)
- if(font_set->charset_list != NULL){
- strcpy(charset_buf,
- font_set->charset_list[0]->encoding_name);
- } else {
- strcpy(charset_buf, "");
- }
- else
- strcpy(charset_buf, font_set->substitute->name);
- } else {
- strcpy(charset_buf, font_set->font_data->name);
- }
- /* Change 1996.01.23 end */
- *charset_list++ = charset_buf;
- charset_buf += strlen(charset_buf) + 1;
- }
- return True;
- }
- static Bool
- create_fontset(XOC oc)
- {
- XOMGenericPart *gen = XOM_GENERIC(oc->core.om);
- int found_num;
- if (init_fontset(oc) == False)
- return False;
- found_num = parse_fontname(oc);
- if (found_num <= 0) {
- if (found_num == 0)
- set_missing_list(oc);
- return False;
- }
- if (gen->on_demand_loading == True) {
- if (load_font_info(oc) == False)
- return False;
- } else {
- if (load_font(oc) == False)
- return False;
- }
- if (init_core_part(oc) == False)
- return False;
- if (set_missing_list(oc) == False)
- return False;
- return True;
- }
- /* For VW/UDC start */
- static void
- free_fontdataOC(Display *dpy, FontData font_data, int font_data_count)
- {
- for( ; font_data_count-- ; font_data++) {
- if(font_data->xlfd_name){
- Xfree(font_data->xlfd_name);
- font_data->xlfd_name = NULL;
- }
- if(font_data->font){ /* ADD 1996.01.7 */
- if(font_data->font->fid) /* Add 1996.01.23 */
- falFreeFont(dpy,font_data->font); /* ADD 1996.01.7 */
- else /* Add 1996.01.23 */
- falFreeFontInfo(NULL, font_data->font, 1);/* Add 1996.01.23 */
- font_data->font = NULL;
- }
- /* XOM to kyoutuu shite shiyou sushiteiru ryouiki
- kokoha free_fontdataOM() de free sareru
- if(font_data->scopes){
- Xfree(font_data->scopes);
- font_data->scopes = NULL;
- }
- if(font_data->name){
- Xfree(font_data->name);
- font_data->name = NULL;
- }
- */
- }
- }
- static void
- destroy_fontdata(XOCGenericPart *gen, Display *dpy)
- {
- FontSet font_set = (FontSet) NULL;
- int font_set_num = 0;
- if (gen->font_set) {
- font_set = gen->font_set;
- font_set_num = gen->font_set_num;
- for( ; font_set_num-- ; font_set++) {
- if(font_set->font_data) {
- free_fontdataOC(dpy,
- font_set->font_data, font_set->font_data_count);
- Xfree(font_set->font_data);
- font_set->font_data = NULL;
- }
- if(font_set->substitute) {
- free_fontdataOC(dpy,
- font_set->substitute, font_set->substitute_num);
- Xfree(font_set->substitute);
- font_set->substitute = NULL;
- }
- if(font_set->vmap) {
- free_fontdataOC(dpy,
- font_set->vmap, font_set->vmap_num);
- Xfree(font_set->vmap);
- font_set->vmap = NULL;
- }
- if(font_set->vrotate) {
- free_fontdataOC(dpy,
- (FontData)font_set->vrotate,
- font_set->vrotate_num);
- Xfree(font_set->vrotate);
- font_set->vrotate = NULL;
- }
- }
- Xfree(gen->font_set);
- gen->font_set = NULL;
- }
- }
- /* For VW/UDC end */
- static void
- destroy_oc(XOC oc)
- {
- Display *dpy = oc->core.om->core.display;
- XOCGenericPart *gen = XOC_GENERIC(oc);
- XFontStruct **font_list, *font;
- FontSet font_set = (FontSet) NULL;
- int font_set_num = 0;
- int count = 0;
- if (gen->mbs_to_cs)
- _fallcCloseConverter(gen->mbs_to_cs);
- if (gen->wcs_to_cs)
- _fallcCloseConverter(gen->wcs_to_cs);
- /* For VW/UDC start */ /* Change 1996.01.8 */
- destroy_fontdata(gen,dpy);
- /*
- */
- /* For VW/UDC end */
- if (oc->core.base_name_list)
- Xfree(oc->core.base_name_list);
- if (oc->core.font_info.font_name_list)
- falFreeStringList(oc->core.font_info.font_name_list);
- if (font_list = oc->core.font_info.font_struct_list) {
- Xfree(oc->core.font_info.font_struct_list);
- }
- if (oc->core.missing_list.charset_list)
- falFreeStringList(oc->core.missing_list.charset_list);
- Xfree(oc);
- }
- static char *
- set_oc_values(XOC oc, XlcArgList args, int num_args)
- {
- if (oc->core.resources == NULL)
- return NULL;
- return _fallcSetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcSetMask);
- }
- static char *
- get_oc_values(XOC oc, XlcArgList args, int num_args)
- {
- if (oc->core.resources == NULL)
- return NULL;
- return _fallcGetValues((XPointer) oc, oc->core.resources,
- oc->core.num_resources, args, num_args, XlcGetMask);
- }
- static XOCMethodsRec oc_default_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _falmbDefaultTextEscapement,
- _falmbDefaultTextExtents,
- _falmbDefaultTextPerCharExtents,
- _falmbDefaultDrawString,
- _falmbDefaultDrawImageString,
- _falwcDefaultTextEscapement,
- _falwcDefaultTextExtents,
- _falwcDefaultTextPerCharExtents,
- _falwcDefaultDrawString,
- _falwcDefaultDrawImageString
- };
- static XOCMethodsRec oc_generic_methods = {
- destroy_oc,
- set_oc_values,
- get_oc_values,
- _falmbGenericTextEscapement,
- _falmbGenericTextExtents,
- _falmbGenericTextPerCharExtents,
- _falmbGenericDrawString,
- _falmbGenericDrawImageString,
- _falwcGenericTextEscapement,
- _falwcGenericTextExtents,
- _falwcGenericTextPerCharExtents,
- _falwcGenericDrawString,
- _falwcGenericDrawImageString
- };
- typedef struct _XOCMethodsListRec {
- char *name;
- XOCMethods methods;
- } XOCMethodsListRec, *XOCMethodsList;
- static XOCMethodsListRec oc_methods_list[] = {
- { "default", &oc_default_methods },
- { "generic", &oc_generic_methods }
- };
- static XlcResource oc_resources[] = {
- { XNBaseFontName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.base_name_list), XlcCreateMask | XlcGetMask },
- { XNOMAutomatic, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOCRec, core.om_automatic), XlcGetMask },
- { XNMissingCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOCRec, core.missing_list), XlcGetMask },
- { XNDefaultString, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.default_string), XlcGetMask },
- { XNOrientation, NULLQUARK, sizeof(XOrientation),
- XOffsetOf(XOCRec, core.orientation), XlcSetMask | XlcGetMask },
- { XNResourceName, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_name), XlcSetMask | XlcGetMask },
- { XNResourceClass, NULLQUARK, sizeof(char *),
- XOffsetOf(XOCRec, core.res_class), XlcSetMask | XlcGetMask },
- { XNFontInfo, NULLQUARK, sizeof(XOMFontInfo),
- XOffsetOf(XOCRec, core.font_info), XlcGetMask }
- };
- static XOC
- create_oc(XOM om, XlcArgList args, int num_args)
- {
- XOC oc;
- XOMGenericPart *gen = XOM_GENERIC(om);
- XOCMethodsList methods_list = oc_methods_list;
- int count;
- oc = (XOC) Xmalloc(sizeof(XOCGenericRec));
- if (oc == NULL)
- return (XOC) NULL;
- bzero((char *) oc, sizeof(XOCGenericRec));
- oc->core.om = om;
- if (oc_resources[0].xrm_name == NULLQUARK)
- _fallcCompileResourceList(oc_resources, XlcNumber(oc_resources));
- if (_fallcSetValues((XPointer) oc, oc_resources, XlcNumber(oc_resources),
- args, num_args, XlcCreateMask | XlcDefaultMask)){
- destroy_oc(oc);
- return (XOC) NULL;
- }
- if (oc->core.base_name_list == NULL){
- destroy_oc(oc);
- return (XOC) NULL;
- }
- oc->core.resources = oc_resources;
- oc->core.num_resources = XlcNumber(oc_resources);
- if (create_fontset(oc) == False){
- destroy_oc(oc);
- return (XOC) NULL;
- }
- oc->methods = &oc_generic_methods;
- if (gen->object_name) {
- count = XlcNumber(oc_methods_list);
- for ( ; count-- > 0; methods_list++) {
- if (!_fallcCompareISOLatin1(gen->object_name, methods_list->name)) {
- oc->methods = methods_list->methods;
- break;
- }
- }
- }
- return oc;
- }
- static void
- free_fontdataOM(FontData font_data, int font_data_count)
- {
- for( ; font_data_count-- ; font_data++) {
- if(font_data->name){
- Xfree(font_data->name);
- font_data->name = NULL;
- }
- if(font_data->scopes){
- Xfree(font_data->scopes);
- font_data->scopes = NULL;
- }
- }
- }
- static Status
- close_om(XOM om)
- {
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- int count;
- if (data = gen->data) {
- for (count = gen->data_num; count-- > 0; data++) {
- if (data->charset_list){
- Xfree(data->charset_list);
- data->charset_list = NULL;
- }
- /* free font_data for om */
- if (data->font_data) {
- free_fontdataOM(data->font_data,data->font_data_count);
- Xfree(data->font_data);
- data->font_data = NULL;
- }
- /* free substitute for om */
- if (data->substitute) {
- free_fontdataOM(data->substitute,data->substitute_num);
- Xfree(data->substitute);
- data->substitute = NULL;
- }
- /* free vmap for om */
- if (data->vmap) {
- free_fontdataOM(data->vmap,data->vmap_num);
- Xfree(data->vmap);
- data->vmap = NULL;
- }
- /* free vrotate for om */
- if (data->vrotate) {
- #ifdef COMMENT
- free_fontdataOM(data->vrotate,data->vrotate_num);
- #endif /* COMMENT */
- Xfree(data->vrotate);
- data->vrotate = NULL;
- }
- }
- Xfree(gen->data);
- gen->data = NULL;
- }
- if (gen->object_name){
- Xfree(gen->object_name);
- gen->object_name = NULL;
- }
- if (om->core.res_name){
- Xfree(om->core.res_name);
- om->core.res_name = NULL;
- }
- if (om->core.res_class){
- Xfree(om->core.res_class);
- om->core.res_class = NULL;
- }
- if (om->core.required_charset.charset_list &&
- om->core.required_charset.charset_count > 0){
- falFreeStringList(om->core.required_charset.charset_list);
- om->core.required_charset.charset_list = NULL;
- } else {
- Xfree((char*)om->core.required_charset.charset_list);
- om->core.required_charset.charset_list = NULL;
- }
- if (om->core.orientation_list.orientation){
- Xfree(om->core.orientation_list.orientation);
- om->core.orientation_list.orientation = NULL;
- }
- Xfree(om);
- return 0;
- }
- static char *
- set_om_values(XOM om, XlcArgList args, int num_args)
- {
- if (om->core.resources == NULL)
- return NULL;
- return _fallcSetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcSetMask);
- }
- static char *
- get_om_values(XOM om, XlcArgList args, int num_args)
- {
- if (om->core.resources == NULL)
- return NULL;
- return _fallcGetValues((XPointer) om, om->core.resources,
- om->core.num_resources, args, num_args, XlcGetMask);
- }
- static XOMMethodsRec methods = {
- close_om,
- set_om_values,
- get_om_values,
- create_oc
- };
- static XlcResource om_resources[] = {
- { XNRequiredCharSet, NULLQUARK, sizeof(XOMCharSetList),
- XOffsetOf(XOMRec, core.required_charset), XlcGetMask },
- { XNQueryOrientation, NULLQUARK, sizeof(XOMOrientation),
- XOffsetOf(XOMRec, core.orientation_list), XlcGetMask },
- { XNDirectionalDependentDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.directional_dependent), XlcGetMask },
- { XNContextualDrawing, NULLQUARK, sizeof(Bool),
- XOffsetOf(XOMRec, core.contextual_drawing), XlcGetMask }
- };
- static XOM
- create_om(
- XLCd lcd,
- Display *dpy,
- XrmDatabase rdb,
- char *res_name,
- char *res_class)
- {
- XOM om;
- om = (XOM) Xmalloc(sizeof(XOMGenericRec));
- if (om == NULL)
- return (XOM) NULL;
- bzero((char *) om, sizeof(XOMGenericRec));
- om->methods = &methods;
- om->core.lcd = lcd;
- om->core.display = dpy;
- om->core.rdb = rdb;
- if (res_name) {
- om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1);
- if (om->core.res_name == NULL){
- close_om(om);
- return (XOM) NULL;
- }
- strcpy(om->core.res_name, res_name);
- }
- if (res_class) {
- om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1);
- if (om->core.res_class == NULL){
- close_om(om);
- return (XOM) NULL;
- }
- strcpy(om->core.res_class, res_class);
- }
- if (om_resources[0].xrm_name == NULLQUARK)
- _fallcCompileResourceList(om_resources, XlcNumber(om_resources));
- om->core.resources = om_resources;
- om->core.num_resources = XlcNumber(om_resources);
- return om;
- }
- static OMData
- add_data(XOM om)
- {
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData new;
- int num;
- if (num = gen->data_num)
- new = (OMData) Xrealloc(gen->data, (num + 1) * sizeof(OMDataRec));
- else
- new = (OMData) Xmalloc(sizeof(OMDataRec));
- if (new == NULL)
- return NULL;
- gen->data_num = num + 1;
- gen->data = new;
- new += num;
- bzero((char *) new, sizeof(OMDataRec));
- return new;
- }
- /* For VW/UDC */
- FontData
- falread_EncodingInfo(int count, char **value)
- {
- FontData font_data,ret;
- char *buf, *bufptr,*scp;
- FontScope scope;
- int len;
- extern FontScope falparse_scopemaps();
- font_data = (FontData) Xmalloc(sizeof(FontDataRec) * count);
- if (font_data == NULL)
- return NULL;
- bzero((char *) font_data, sizeof(FontDataRec) * count);
- ret = font_data;
- for ( ; count-- > 0; font_data++) {
- /*
- strcpy(buf, *value++);
- */
- buf = *value; value++;
- if (bufptr = strchr(buf, ':')){
- len = (int)(bufptr - buf);
- bufptr++ ;
- }
- font_data->name = (char *) Xmalloc(len + 1);
- if (font_data->name == NULL) {
- XFree(font_data);
- return NULL;
- }
- strncpy(font_data->name, buf,len);
- font_data->name[len] = 0;
- if (bufptr && _fallcCompareISOLatin1(bufptr, "GL") == 0)
- font_data->side = XlcGL;
- else if (bufptr && _fallcCompareISOLatin1(bufptr, "GR") == 0)
- font_data->side = XlcGR;
- else
- font_data->side = XlcGLGR;
- if (bufptr && (scp = strchr(bufptr, '['))){
- font_data->scopes = falparse_scopemaps(scp,&(font_data->scopes_num));
- }
- }
- return(ret);
- }
- static CodeRange read_vrotate(
- int count,
- char **value,
- int *type,
- int *vrotate_num)
- {
- FontData font_data,ret;
- char *buf, *bufptr,*scp;
- CodeRange range;
- extern FontScope falparse_scopemaps();
- if(!strcmp(value[0],"all")){
- *type = VROTATE_ALL ;
- *vrotate_num = 0 ;
- return (NULL);
- } else if(*(value[0]) == '['){
- *type = VROTATE_PART ;
- range = (CodeRange)falparse_scopemaps(value[0],vrotate_num);
- return (range);
- } else {
- *type = VROTATE_NONE ;
- *vrotate_num = 0 ;
- return (NULL);
- }
- }
- static void
- read_vw(XLCd lcd, OMData font_set, int num)
- {
- char **value, buf[BUFSIZ], *bufptr;
- int count,i;
- snprintf(buf, sizeof(buf), "fs%d.font.vertical_map", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- dbg_printValue(buf,value,count);
- font_set->vmap_num = count;
- font_set->vmap = falread_EncodingInfo(count,value);
- }
- snprintf(buf, sizeof(buf), "fs%d.font.vertical_rotate", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- dbg_printValue(buf,value,count);
- font_set->vrotate = read_vrotate(count,value,&(font_set->vrotate_type),
- &(font_set->vrotate_num));
- }
- }
- /* VW/UDC end */
- static Bool
- init_om(XOM om)
- {
- XLCd lcd = om->core.lcd;
- XOMGenericPart *gen = XOM_GENERIC(om);
- OMData data;
- XlcCharSet *charset_list;
- FontData font_data;
- char **required_list;
- XOrientation *orientation;
- char **value, buf[BUFSIZ], *bufptr;
- int count = 0, num = 0, length = 0;
- _fallcGetResource(lcd, "XLC_FONTSET", "on_demand_loading", &value, &count);
- if (count > 0 && _fallcCompareISOLatin1(*value, "True") == 0)
- gen->on_demand_loading = True;
- _fallcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
- if (count > 0) {
- gen->object_name = (char *) Xmalloc(strlen(*value) + 1);
- if (gen->object_name == NULL)
- return False;
- strcpy(gen->object_name, *value);
- }
- for (num = 0; ; num++) {
- snprintf(buf, sizeof(buf), "fs%d.charset.name", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if( count < 1){
- snprintf(buf, sizeof(buf), "fs%d.charset", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1)
- break;
- }
- data = add_data(om);
- if (data == NULL)
- return False;
- charset_list = (XlcCharSet *) Xmalloc(sizeof(XlcCharSet) * count);
- if (charset_list == NULL)
- return False;
- data->charset_list = charset_list;
- data->charset_count = count;
- while (count-- > 0){
- *charset_list++ = _fallcGetCharSet(*value++);
- }
- snprintf(buf, sizeof(buf), "fs%d.charset.udc_area", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if( count > 0){
- UDCArea udc;
- int i,flag = 0;
- udc = (UDCArea)Xmalloc(count * sizeof(UDCAreaRec));
- if (udc == NULL)
- return False;
- for(i=0;i<count;i++){
- sscanf(value[i],"\\x%lx,\\x%lx", &(udc[i].start), &(udc[i].end));
- }
- for(i=0;i<data->charset_count;i++){
- if(data->charset_list[i]->udc_area == NULL){
- data->charset_list[i]->udc_area = udc;
- data->charset_list[i]->udc_area_num = count;
- flag = 1;
- }
- }
- if(flag == 0){
- Xfree(udc);
- }
- }
- snprintf(buf, sizeof(buf), "fs%d.font.primary", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1){
- snprintf(buf, sizeof(buf), "fs%d.font", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1)
- return False;
- }
- font_data = falread_EncodingInfo(count,value);
- if (font_data == NULL)
- return False;
- data->font_data = font_data;
- data->font_data_count = count;
- snprintf(buf, sizeof(buf), "fs%d.font.substitute", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count > 0){
- font_data = falread_EncodingInfo(count,value);
- if (font_data == NULL)
- return False;
- data->substitute = font_data;
- data->substitute_num = count;
- } else {
- snprintf(buf, sizeof(buf), "fs%d.font", num);
- _fallcGetResource(lcd, "XLC_FONTSET", buf, &value, &count);
- if (count < 1) {
- data->substitute = NULL;
- data->substitute_num = 0;
- } else {
- font_data = falread_EncodingInfo(count,value);
- data->substitute = font_data;
- data->substitute_num = count;
- }
- }
- read_vw(lcd,data,num);
- length += strlen(data->font_data->name) + 1;
- }
- /* required charset list */
- required_list = (char **) Xmalloc(sizeof(char *) * gen->data_num);
- if (required_list == NULL)
- return False;
- bufptr = (char *) Xmalloc(length);
- if (bufptr == NULL) {
- Xfree(required_list);
- return False;
- }
- om->core.required_charset.charset_list = required_list;
- om->core.required_charset.charset_count = gen->data_num;
- count = gen->data_num;
- data = gen->data;
- for ( ; count-- > 0; data++) {
- strcpy(bufptr, data->font_data->name);
- *required_list++ = bufptr;
- bufptr += strlen(bufptr) + 1;
- }
- /* orientation list */
- orientation = (XOrientation *) Xmalloc(sizeof(XOrientation) * 2);
- if (orientation == NULL)
- return False;
- orientation[0] = XOMOrientation_LTR_TTB;
- orientation[1] = XOMOrientation_TTB_RTL;
- om->core.orientation_list.orientation = orientation;
- om->core.orientation_list.num_orientation = 2;
- /* directional dependent drawing */
- om->core.directional_dependent = False;
- /* contexual drawing */
- om->core.contextual_drawing = False;
- /* context dependent */
- om->core.context_dependent = False;
- return True;
- }
- XOM
- _falomGenericOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
- char *res_name, char *res_class)
- {
- XOM om;
- om = create_om(lcd, dpy, rdb, res_name, res_class);
- if (om == NULL)
- return (XOM) NULL;
- if (init_om(om) == False){
- close_om(om);
- return (XOM) NULL;
- }
- return om;
- }
- Bool
- _falInitOM(XLCd lcd)
- {
- lcd->methods->open_om = _falomGenericOpenOM;
- return True;
- }
|