LCOV - code coverage report
Current view: top level - fontforgeexe - encodingui.c (source / functions) Hit Total Coverage
Test: FontForge coverage report 2017-08-04 01:21:11+02:00 (commit d35f7e4107a9e1db65cce47c468fcc914cecb8fd) Lines: 0 354 0.0 %
Date: 2017-08-04 Functions: 0 18 0.0 %

          Line data    Source code
       1             : /* -*- coding: utf-8 -*- */
       2             : /* Copyright (C) 2000-2012 by George Williams */
       3             : /*
       4             :  * Redistribution and use in source and binary forms, with or without
       5             :  * modification, are permitted provided that the following conditions are met:
       6             : 
       7             :  * Redistributions of source code must retain the above copyright notice, this
       8             :  * list of conditions and the following disclaimer.
       9             : 
      10             :  * Redistributions in binary form must reproduce the above copyright notice,
      11             :  * this list of conditions and the following disclaimer in the documentation
      12             :  * and/or other materials provided with the distribution.
      13             : 
      14             :  * The name of the author may not be used to endorse or promote products
      15             :  * derived from this software without specific prior written permission.
      16             : 
      17             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
      18             :  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
      19             :  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
      20             :  * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
      21             :  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
      22             :  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
      23             :  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
      24             :  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
      25             :  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
      26             :  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             :  */
      28             : 
      29             : #include "bitmapchar.h"
      30             : #include "fontforgeui.h"
      31             : #include <ustring.h>
      32             : #include <utype.h>
      33             : #include <unistd.h>
      34             : #include <sys/types.h>
      35             : #include <dirent.h>
      36             : #include <gfile.h>
      37             : #include <gresource.h>
      38             : #include "plugins.h"
      39             : #include "encoding.h"
      40             : 
      41           0 : static GTextInfo *EncodingList(void) {
      42             :     GTextInfo *ti;
      43             :     int i;
      44             :     Encoding *item;
      45             : 
      46           0 :     i = 0;
      47           0 :     for ( item=enclist; item!=NULL ; item=item->next )
      48           0 :         if ( !item->builtin )
      49           0 :             ++i;
      50           0 :     ti = calloc(i+1,sizeof(GTextInfo));
      51           0 :     i = 0;
      52           0 :     for ( item=enclist; item!=NULL ; item=item->next )
      53           0 :         if ( !item->builtin )
      54           0 :             ti[i++].text = uc_copy(item->enc_name);
      55           0 :     if ( i!=0 )
      56           0 :         ti[0].selected = true;
      57           0 : return( ti );
      58             : }
      59             : 
      60             : #define CID_Encodings   1001
      61             : 
      62           0 : static int DE_Delete(GGadget *g, GEvent *e) {
      63             :     GWindow gw;
      64             :     int *done;
      65             :     GGadget *list;
      66             :     int sel,i;
      67             :     Encoding *item;
      68             : 
      69           0 :     if ( e->type==et_controlevent &&
      70           0 :             (e->u.control.subtype == et_buttonactivate ||
      71           0 :              e->u.control.subtype == et_listdoubleclick )) {
      72           0 :         gw = GGadgetGetWindow(g);
      73           0 :         done = GDrawGetUserData(gw);
      74           0 :         list = GWidgetGetControl(gw,CID_Encodings);
      75           0 :         sel = GGadgetGetFirstListSelectedItem(list);
      76           0 :         i=0;
      77           0 :         for ( item=enclist; item!=NULL; item=item->next ) {
      78           0 :             if ( item->builtin )
      79             :                 /* Do Nothing */;
      80           0 :             else if ( i==sel )
      81           0 :         break;
      82             :             else
      83           0 :                 ++i;
      84             :         }
      85           0 :         if ( item!=NULL )
      86           0 :             DeleteEncoding(item);
      87           0 :         *done = true;
      88             :     }
      89           0 : return( true );
      90             : }
      91             : 
      92           0 : static int DE_Cancel(GGadget *g, GEvent *e) {
      93             :     GWindow gw;
      94             :     int *done;
      95             : 
      96           0 :     if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
      97           0 :         gw = GGadgetGetWindow(g);
      98           0 :         done = GDrawGetUserData(gw);
      99           0 :         *done = true;
     100             :     }
     101           0 : return( true );
     102             : }
     103             : 
     104           0 : static int de_e_h(GWindow gw, GEvent *event) {
     105           0 :     if ( event->type==et_close ) {
     106           0 :         int *done = GDrawGetUserData(gw);
     107           0 :         *done = true;
     108           0 :     } else if ( event->type == et_char ) {
     109           0 : return( false );
     110             :     }
     111           0 : return( true );
     112             : }
     113             : 
     114           0 : void RemoveEncoding(void) {
     115             :     GRect pos;
     116             :     GWindow gw;
     117             :     GWindowAttrs wattrs;
     118             :     GGadgetCreateData gcd[5];
     119             :     GTextInfo label[5];
     120             :     Encoding *item;
     121           0 :     int done = 0;
     122             : 
     123           0 :     for ( item=enclist; item!=NULL && item->builtin; item=item->next );
     124           0 :     if ( item==NULL )
     125           0 : return;
     126             : 
     127           0 :     memset(&gcd,0,sizeof(gcd));
     128           0 :     memset(&label,0,sizeof(label));
     129           0 :     memset(&wattrs,0,sizeof(wattrs));
     130           0 :     wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_undercursor|wam_restrict|wam_isdlg;
     131           0 :     wattrs.event_masks = ~(1<<et_charup);
     132           0 :     wattrs.restrict_input_to_me = 1;
     133           0 :     wattrs.is_dlg = 1;
     134           0 :     wattrs.undercursor = 1;
     135           0 :     wattrs.cursor = ct_pointer;
     136           0 :     wattrs.utf8_window_title = _("Remove Encoding");
     137           0 :     pos.x = pos.y = 0;
     138           0 :     pos.width = GGadgetScale(GDrawPointsToPixels(NULL,150));
     139           0 :     pos.height = GDrawPointsToPixels(NULL,110);
     140           0 :     gw = GDrawCreateTopWindow(NULL,&pos,de_e_h,&done,&wattrs);
     141             : 
     142           0 :     gcd[0].gd.pos.x = 10; gcd[0].gd.pos.y = 6;
     143           0 :     gcd[0].gd.pos.width = 130; gcd[0].gd.pos.height = 5*12+10;
     144           0 :     gcd[0].gd.flags = gg_visible | gg_enabled;
     145           0 :     gcd[0].gd.cid = CID_Encodings;
     146           0 :     gcd[0].gd.u.list = EncodingList();
     147           0 :     gcd[0].gd.handle_controlevent = DE_Delete;
     148           0 :     gcd[0].creator = GListCreate;
     149             : 
     150           0 :     gcd[2].gd.pos.x = -10; gcd[2].gd.pos.y = gcd[0].gd.pos.y+gcd[0].gd.pos.height+5;
     151           0 :     gcd[2].gd.pos.width = -1; gcd[2].gd.pos.height = 0;
     152           0 :     gcd[2].gd.flags = gg_visible | gg_enabled | gg_but_cancel ;
     153           0 :     label[2].text = (unichar_t *) _("_Cancel");
     154           0 :     label[2].text_is_1byte = true;
     155           0 :     label[2].text_in_resource = true;
     156           0 :     gcd[2].gd.label = &label[2];
     157           0 :     gcd[2].gd.mnemonic = 'C';
     158           0 :     gcd[2].gd.handle_controlevent = DE_Cancel;
     159           0 :     gcd[2].creator = GButtonCreate;
     160             : 
     161           0 :     gcd[1].gd.pos.x = 10-3; gcd[1].gd.pos.y = gcd[2].gd.pos.y-3;
     162           0 :     gcd[1].gd.pos.width = -1; gcd[1].gd.pos.height = 0;
     163           0 :     gcd[1].gd.flags = gg_visible | gg_enabled | gg_but_default ;
     164           0 :     label[1].text = (unichar_t *) _("_Delete");
     165           0 :     label[1].text_is_1byte = true;
     166           0 :     label[1].text_in_resource = true;
     167           0 :     gcd[1].gd.mnemonic = 'D';
     168           0 :     gcd[1].gd.label = &label[1];
     169           0 :     gcd[1].gd.handle_controlevent = DE_Delete;
     170           0 :     gcd[1].creator = GButtonCreate;
     171             : 
     172           0 :     gcd[3].gd.pos.x = 2; gcd[3].gd.pos.y = 2;
     173           0 :     gcd[3].gd.pos.width = pos.width-4; gcd[3].gd.pos.height = pos.height-2;
     174           0 :     gcd[3].gd.flags = gg_enabled | gg_visible | gg_pos_in_pixels;
     175           0 :     gcd[3].creator = GGroupCreate;
     176             : 
     177           0 :     GGadgetsCreate(gw,gcd);
     178           0 :     GTextInfoListFree(gcd[0].gd.u.list);
     179             : 
     180           0 :     GWidgetHidePalettes();
     181           0 :     GDrawSetVisible(gw,true);
     182           0 :     while ( !done )
     183           0 :         GDrawProcessOneEvent(NULL);
     184           0 :     GDrawDestroyWindow(gw);
     185             : }
     186             : 
     187           0 : Encoding *MakeEncoding(SplineFont *sf,EncMap *map) {
     188             :     char *name;
     189             :     int i, gid;
     190             :     Encoding *item, *temp;
     191             :     SplineChar *sc;
     192             : 
     193           0 :     if ( map->enc!=&custom )
     194           0 : return(NULL);
     195             : 
     196           0 :     name = gwwv_ask_string(_("Please name this encoding"),NULL,_("Please name this encoding"));
     197           0 :     if ( name==NULL )
     198           0 : return(NULL);
     199           0 :     item = calloc(1,sizeof(Encoding));
     200           0 :     item->enc_name = name;
     201           0 :     item->only_1byte = item->has_1byte = true;
     202           0 :     item->char_cnt = map->enccount;
     203           0 :     item->unicode = calloc(map->enccount,sizeof(int32));
     204           0 :     for ( i=0; i<map->enccount; ++i ) if ( (gid = map->map[i])!=-1 && (sc=sf->glyphs[gid])!=NULL ) {
     205           0 :         if ( sc->unicodeenc!=-1 )
     206           0 :             item->unicode[i] = sc->unicodeenc;
     207           0 :         else if ( strcmp(sc->name,".notdef")!=0 ) {
     208           0 :             if ( item->psnames==NULL )
     209           0 :                 item->psnames = calloc(map->enccount,sizeof(unichar_t *));
     210           0 :             item->psnames[i] = copy(sc->name);
     211             :         }
     212             :     }
     213           0 :     RemoveMultiples(item);
     214             : 
     215           0 :     if ( enclist == NULL )
     216           0 :         enclist = item;
     217             :     else {
     218           0 :         for ( temp=enclist; temp->next!=NULL; temp=temp->next );
     219           0 :         temp->next = item;
     220             :     }
     221           0 :     DumpPfaEditEncodings();
     222           0 : return( item );
     223             : }
     224             : 
     225           0 : void LoadEncodingFile(void) {
     226             :     static char filter[] = "*{.ps,.PS,.txt,.TXT,.enc,.ENC,GlyphOrderAndAliasDB}";
     227             :     char *fn;
     228             :     char *filename;
     229             : 
     230           0 :     fn = gwwv_open_filename(_("Load Encoding"), NULL, filter, NULL);
     231           0 :     if ( fn==NULL )
     232           0 : return;
     233           0 :     filename = utf82def_copy(fn);
     234           0 :     ParseEncodingFile(filename, NULL);
     235           0 :     free(fn); free(filename);
     236           0 :     DumpPfaEditEncodings();
     237             : }
     238             : 
     239           0 : void SFFindNearTop(SplineFont *sf) {
     240             :     FontView *fv;
     241             :     EncMap *map;
     242             :     int i,k,gid;
     243             : 
     244           0 :     if ( sf->cidmaster!=NULL )
     245           0 :         sf = sf->cidmaster;
     246           0 :     if ( sf->subfontcnt==0 ) {
     247           0 :         for ( fv=(FontView *) sf->fv; fv!=NULL; fv=(FontView *) (fv->b.nextsame) ) {
     248           0 :             map = fv->b.map;
     249           0 :             fv->sc_near_top = NULL;
     250           0 :             for ( i=fv->rowoff*fv->colcnt; i<map->enccount && i<(fv->rowoff+fv->rowcnt)*fv->colcnt; ++i )
     251           0 :                 if ( (gid=map->map[i])!=-1 && sf->glyphs[gid]!=NULL ) {
     252           0 :                     fv->sc_near_top = sf->glyphs[gid];
     253           0 :             break;
     254             :                 }
     255             :         }
     256             :     } else {
     257           0 :         for ( fv=(FontView *) sf->fv; fv!=NULL; fv=(FontView *) (fv->b.nextsame) ) {
     258           0 :             map = fv->b.map;
     259           0 :             fv->sc_near_top = NULL;
     260           0 :             for ( i=fv->rowoff*fv->colcnt; i<map->enccount && i<(fv->rowoff+fv->rowcnt)*fv->colcnt; ++i ) {
     261           0 :                 for ( k=0; k<sf->subfontcnt; ++k )
     262           0 :                     if ( (gid=map->map[i])!=-1 &&
     263           0 :                             gid<sf->subfonts[k]->glyphcnt &&
     264           0 :                             sf->subfonts[k]->glyphs[gid]!=NULL )
     265           0 :                         fv->sc_near_top = sf->subfonts[k]->glyphs[gid];
     266             :             }
     267             :         }
     268             :     }
     269           0 : }
     270             : 
     271           0 : void SFRestoreNearTop(SplineFont *sf) {
     272             :     FontView *fv;
     273             : 
     274           0 :     for ( fv=(FontView *) sf->fv; fv!=NULL; fv=(FontView *) (fv->b.nextsame) ) if ( fv->sc_near_top!=NULL ) {
     275             :         /* Note: For CID keyed fonts, we don't care if sc is in the currently */
     276             :         /*  displayed font, all we care about is the CID */
     277           0 :         int enc = fv->b.map->backmap[fv->sc_near_top->orig_pos];
     278           0 :         if ( enc!=-1 ) {
     279           0 :             fv->rowoff = enc/fv->colcnt;
     280           0 :             GScrollBarSetPos(fv->vsb,fv->rowoff);
     281             :             /* Don't ask for an expose event yet. We'll get one soon enough */
     282             :         }
     283             :     }
     284           0 : }
     285             : 
     286             : struct block {
     287             :     int cur, tot;
     288             :     char **maps;
     289             :     char **dirs;
     290             : };
     291             : 
     292           0 : static void AddToBlock(struct block *block,char *mapname, char *dir) {
     293             :     int i, val, j;
     294           0 :     int len = strlen(mapname);
     295             : 
     296           0 :     if ( mapname[len-7]=='.' ) len -= 7;
     297           0 :     for ( i=0; i<block->cur; ++i ) {
     298           0 :         if ( (val=strncmp(block->maps[i],mapname,len))==0 )
     299           0 : return;         /* Duplicate */
     300           0 :         else if ( val>0 )
     301           0 :     break;
     302             :     }
     303           0 :     if ( block->tot==0 ) {
     304           0 :         block->tot = 10;
     305           0 :         block->maps = malloc(10*sizeof(char *));
     306           0 :         block->dirs = malloc(10*sizeof(char *));
     307           0 :     } else if ( block->cur>=block->tot ) {
     308           0 :         block->tot += 10;
     309           0 :         block->maps = realloc(block->maps,block->tot*sizeof(char *));
     310           0 :         block->dirs = realloc(block->dirs,block->tot*sizeof(char *));
     311             :     }
     312           0 :     for ( j=block->cur; j>=i; --j ) {
     313           0 :         block->maps[j+1] = block->maps[j];
     314           0 :         block->dirs[j+1] = block->dirs[j];
     315             :     }
     316           0 :     block->maps[i] = copyn(mapname,len);
     317           0 :     block->dirs[i] = dir;
     318           0 :     ++block->cur;
     319             : }
     320             : 
     321           0 : static void FindMapsInDir(struct block *block,char *dir) {
     322             :     struct dirent *ent;
     323             :     DIR *d;
     324             :     int len;
     325             :     char *pt, *pt2;
     326             : 
     327           0 :     if ( dir==NULL )
     328           0 : return;
     329             :     /* format of cidmap filename "?*-?*-[0-9]*.cidmap" */
     330           0 :     d = opendir(dir);
     331           0 :     if ( d==NULL )
     332           0 : return;
     333           0 :     while ( (ent = readdir(d))!=NULL ) {
     334           0 :         if ( (len = strlen(ent->d_name))<8 )
     335           0 :     continue;
     336           0 :         if ( strcmp(ent->d_name+len-7,".cidmap")!=0 )
     337           0 :     continue;
     338           0 :         pt = strchr(ent->d_name, '-');
     339           0 :         if ( pt==NULL || pt==ent->d_name )
     340           0 :     continue;
     341           0 :         pt2 = strchr(pt+1, '-' );
     342           0 :         if ( pt2==NULL || pt2==pt+1 || !isdigit(pt2[1]))
     343           0 :     continue;
     344           0 :         AddToBlock(block,ent->d_name,dir);
     345             :     }
     346           0 :     closedir(d);
     347             : }
     348             : 
     349           0 : static void FindMapsInNoLibsDir(struct block *block,char *dir) {
     350             : 
     351           0 :     if ( dir==NULL || strstr(dir,"/.libs")==NULL )
     352           0 : return;
     353             : 
     354           0 :     dir = copy(dir);
     355           0 :     *strstr(dir,"/.libs") = '\0';
     356             : 
     357           0 :     FindMapsInDir(block,dir);
     358           0 :     free(dir);
     359             : }
     360             : 
     361           0 : struct cidmap *AskUserForCIDMap(void) {
     362             :     struct block block;
     363           0 :     struct cidmap *map = NULL;
     364             :     char buffer[200];
     365             :     char **choices;
     366             :     int i,ret;
     367           0 :     char *filename=NULL;
     368             :     char *reg, *ord, *pt;
     369             :     int supplement;
     370             : 
     371           0 :     memset(&block,'\0',sizeof(block));
     372           0 :     for ( map = cidmaps; map!=NULL; map = map->next ) {
     373           0 :         sprintf(buffer,"%s-%s-%d", map->registry, map->ordering, map->supplement);
     374           0 :         AddToBlock(&block,buffer,NULL);
     375             :     }
     376           0 :     FindMapsInDir(&block,".");
     377           0 :     FindMapsInDir(&block,GResourceProgramDir);
     378           0 :     FindMapsInNoLibsDir(&block,GResourceProgramDir);
     379           0 :     FindMapsInDir(&block,getFontForgeShareDir());
     380           0 :     FindMapsInDir(&block,"/usr/share/fontforge");
     381             : 
     382           0 :     choices = calloc(block.cur+2,sizeof(unichar_t *));
     383           0 :     choices[0] = copy(_("Browse..."));
     384           0 :     for ( i=0; i<block.cur; ++i )
     385           0 :         choices[i+1] = copy(block.maps[i]);
     386           0 :     ret = gwwv_choose(_("Find a cidmap file..."),(const char **) choices,i+1,0,_("Please select a CID ordering"));
     387           0 :     for ( i=0; i<=block.cur; ++i )
     388           0 :         free( choices[i] );
     389           0 :     free(choices);
     390           0 :     if ( ret==0 ) {
     391           0 :         filename = gwwv_open_filename(_("Find a cidmap file..."),NULL,
     392             :                 "?*-?*-[0-9]*.cidmap",NULL);
     393           0 :         if ( filename==NULL )
     394           0 :             ret = -1;
     395             :     }
     396           0 :     if ( ret!=-1 ) {
     397           0 :         if ( filename!=NULL )
     398             :             /* Do nothing for now */;
     399           0 :         else if ( block.dirs[ret-1]!=NULL ) {
     400           0 :             filename = malloc(strlen(block.dirs[ret-1])+strlen(block.maps[ret-1])+3+8);
     401           0 :             strcpy(filename,block.dirs[ret-1]);
     402           0 :             strcat(filename,"/");
     403           0 :             strcat(filename,block.maps[ret-1]);
     404           0 :             strcat(filename,".cidmap");
     405             :         }
     406           0 :         if ( ret!=0 )
     407           0 :             reg = block.maps[ret-1];
     408             :         else {
     409           0 :             reg = strrchr(filename,'/');
     410           0 :             if ( reg==NULL ) reg = filename;
     411           0 :             else ++reg;
     412           0 :             reg = copy(reg);
     413             :         }
     414           0 :         pt = strchr(reg,'-');
     415           0 :         if ( pt==NULL )
     416           0 :             ret = -1;
     417             :         else {
     418           0 :             *pt = '\0';
     419           0 :             ord = pt+1;
     420           0 :             pt = strchr(ord,'-');
     421           0 :             if ( pt==NULL )
     422           0 :                 ret = -1;
     423             :             else {
     424           0 :                 *pt = '\0';
     425           0 :                 supplement = strtol(pt+1,NULL,10);
     426             :             }
     427             :         }
     428           0 :         if ( ret == -1 )
     429             :             /* No map */;
     430           0 :         else if ( filename==NULL )
     431           0 :             map = FindCidMap(reg,ord,supplement,NULL);
     432             :         else {
     433           0 :             map = LoadMapFromFile(filename,reg,ord,supplement);
     434           0 :             free(filename);
     435             :         }
     436           0 :         if ( ret!=0 && reg!=block.maps[ret-1] )
     437           0 :             free(reg);
     438             :         /*free(filename);*/     /* Freed by loadmap */
     439             :     }
     440           0 :     for ( i=0; i<block.cur; ++i )
     441           0 :         free( block.maps[i]);
     442           0 :     free(block.maps);
     443           0 :     free(block.dirs);
     444           0 : return( map );
     445             : }
     446             : 
     447             : GTextInfo encodingtypes[] = {
     448             :     { (unichar_t *) N_("Custom"), NULL, 0, 0, (void *) "Custom", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     449             :     { (unichar_t *) N_("Encoding|Glyph Order"), NULL, 0, 0, (void *) "Original", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     450             :     { NULL, NULL, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},   /* Line */
     451             :     { (unichar_t *) N_("ISO 8859-1  (Latin1)"), NULL, 0, 0, (void *) "iso8859-1", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     452             :     { (unichar_t *) N_("ISO 8859-15  (Latin0)"), NULL, 0, 0, (void *) "iso8859-15", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     453             :     { (unichar_t *) N_("ISO 8859-2  (Latin2)"), NULL, 0, 0, (void *) "iso8859-2", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     454             :     { (unichar_t *) N_("ISO 8859-3  (Latin3)"), NULL, 0, 0, (void *) "iso8859-3", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     455             :     { (unichar_t *) N_("ISO 8859-4  (Latin4)"), NULL, 0, 0, (void *) "iso8859-4", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     456             :     { (unichar_t *) N_("ISO 8859-9  (Latin5)"), NULL, 0, 0, (void *) "iso8859-9", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     457             :     { (unichar_t *) N_("ISO 8859-10  (Latin6)"), NULL, 0, 0, (void *) "iso8859-10", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     458             :     { (unichar_t *) N_("ISO 8859-13  (Latin7)"), NULL, 0, 0, (void *) "iso8859-13", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     459             :     { (unichar_t *) N_("ISO 8859-14  (Latin8)"), NULL, 0, 0, (void *) "iso8859-14", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     460             :     { (unichar_t *) N_("ISO 8859-16  (Latin10)"), NULL, 0, 0, (void *) "iso8859-16", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     461             :     { NULL, NULL, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},   /* Line */
     462             :     { (unichar_t *) N_("ISO 8859-5 (Cyrillic)"), NULL, 0, 0, (void *) "iso8859-5", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     463             :     { (unichar_t *) N_("KOI8-R (Cyrillic)"), NULL, 0, 0, (void *) "koi8-r", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     464             :     { (unichar_t *) N_("ISO 8859-6 (Arabic)"), NULL, 0, 0, (void *) "iso8859-6", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     465             :     { (unichar_t *) N_("ISO 8859-7 (Greek)"), NULL, 0, 0, (void *) "iso8859-7", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     466             :     { (unichar_t *) N_("ISO 8859-8 (Hebrew)"), NULL, 0, 0, (void *) "iso8859-8", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     467             :     { (unichar_t *) N_("ISO 8859-11 (Thai)"), NULL, 0, 0, (void *) "iso8859-11", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     468             :     { NULL, NULL, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},   /* Line */
     469             :     { (unichar_t *) N_("Macintosh Latin"), NULL, 0, 0, (void *) "mac", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     470             :     { (unichar_t *) N_("Windows Latin (\"ANSI\")"), NULL, 0, 0, (void *) "win", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     471             :     { (unichar_t *) N_("Adobe Standard"), NULL, 0, 0, (void *) "AdobeStandard", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     472             :     { (unichar_t *) N_("Symbol"), NULL, 0, 0, (void *) "Symbol", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     473             :     { (unichar_t *) NU_("ΤεΧ Base (8r)"), NULL, 0, 0, (void *) "TeX-Base-Encoding", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     474             :     { NULL, NULL, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},   /* Line */
     475             :     { (unichar_t *) N_("ISO 10646-1 (Unicode, BMP)"), NULL, 0, 0, (void *) "UnicodeBmp", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     476             :     { (unichar_t *) N_("ISO 10646-1 (Unicode, Full)"), NULL, 0, 0, (void *) "UnicodeFull", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     477             :     /*{ (unichar_t *) N_("ISO 10646-? (by plane) ..."), NULL, 0, 0, (void *) em_unicodeplanes, NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' }, */
     478             :     { NULL, NULL, 0, 0, NULL, NULL, 1, 0, 0, 0, 0, 1, 0, 0, 0, '\0'},   /* Line */
     479             :     { (unichar_t *) N_("SJIS (Kanji)"), NULL, 0, 0, (void *) "sjis", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     480             :     { (unichar_t *) N_("JIS 208 (Kanji)"), NULL, 0, 0, (void *) "jis208", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     481             :     { (unichar_t *) N_("JIS 212 (Kanji)"), NULL, 0, 0, (void *) "jis212", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     482             :     { (unichar_t *) N_("Wansung (Korean)"), NULL, 0, 0, (void *) "wansung", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     483             :     { (unichar_t *) N_("KSC 5601-1987 (Korean)"), NULL, 0, 0, (void *) "ksc5601", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     484             :     { (unichar_t *) N_("Johab (Korean)"), NULL, 0, 0, (void *) "johab", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     485             :     { (unichar_t *) N_("GB 2312 (Simp. Chinese)"), NULL, 0, 0, (void *) "gb2312", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     486             :     { (unichar_t *) N_("EUC GB 2312 (Chinese)"), NULL, 0, 0, (void *) "gb2312pk", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     487             :     { (unichar_t *) N_("Big5 (Trad. Chinese)"), NULL, 0, 0, (void *) "big5", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     488             :     { (unichar_t *) N_("Big5 HKSCS (Trad. Chinese)"), NULL, 0, 0, (void *) "big5hkscs", NULL, 0, 0, 0, 0, 0, 0, 1, 0, 0, '\0' },
     489             :     GTEXTINFO_EMPTY
     490             : };
     491             : 
     492           0 : static void EncodingInit(void) {
     493             :     int i;
     494             :     static int done = false;
     495             : 
     496           0 :     if ( done )
     497           0 : return;
     498           0 :     done = true;
     499           0 :     for ( i=0; i<sizeof(encodingtypes)/sizeof(encodingtypes[0])-1; ++i ) {
     500           0 :         if ( !encodingtypes[i].line )
     501           0 :             encodingtypes[i].text = (unichar_t *) S_((char *) encodingtypes[i].text);
     502             :     }
     503             : }
     504             : 
     505           0 : GMenuItem *GetEncodingMenu(void (*func)(GWindow,GMenuItem *,GEvent *),
     506             :         Encoding *current) {
     507             :     GMenuItem *mi;
     508             :     int i, cnt;
     509             :     Encoding *item;
     510             : 
     511           0 :     EncodingInit();
     512             : 
     513           0 :     cnt = 0;
     514           0 :     for ( item=enclist; item!=NULL ; item=item->next )
     515           0 :         if ( !item->hidden )
     516           0 :             ++cnt;
     517           0 :     i = cnt+1;
     518           0 :     i += sizeof(encodingtypes)/sizeof(encodingtypes[0]);
     519           0 :     mi = calloc(i+1,sizeof(GMenuItem));
     520           0 :     for ( i=0; i<sizeof(encodingtypes)/sizeof(encodingtypes[0])-1; ++i ) {
     521           0 :         mi[i].ti = encodingtypes[i];
     522           0 :         if ( !mi[i].ti.line ) {
     523           0 :             mi[i].ti.text = utf82u_copy((char *) (mi[i].ti.text));
     524           0 :             mi[i].ti.checkable = true;
     525           0 :             if ( strmatch(mi[i].ti.userdata,current->enc_name)==0 ||
     526           0 :                     (current->iconv_name!=NULL && strmatch(mi[i].ti.userdata,current->iconv_name)==0))
     527           0 :                 mi[i].ti.checked = true;
     528             :         }
     529           0 :         mi[i].ti.text_is_1byte = false;
     530           0 :         mi[i].ti.fg = mi[i].ti.bg = COLOR_DEFAULT;
     531           0 :         mi[i].invoke = func;
     532             :     }
     533           0 :     if ( cnt!=0 ) {
     534           0 :         mi[i].ti.fg = mi[i].ti.bg = COLOR_DEFAULT;
     535           0 :         mi[i++].ti.line = true;
     536           0 :         for ( item=enclist; item!=NULL ; item=item->next )
     537           0 :             if ( !item->hidden ) {
     538           0 :                 mi[i].ti.text = utf82u_copy(item->enc_name);
     539           0 :                 mi[i].ti.userdata = (void *) item->enc_name;
     540           0 :                 mi[i].ti.fg = mi[i].ti.bg = COLOR_DEFAULT;
     541           0 :                 mi[i].ti.checkable = true;
     542           0 :                 if ( item==current )
     543           0 :                     mi[i].ti.checked = true;
     544           0 :                 mi[i++].invoke = func;
     545             :             }
     546             :     }
     547           0 : return( mi );
     548             : }
     549             : 
     550           0 : GTextInfo *GetEncodingTypes(void) {
     551             :     GTextInfo *ti;
     552             :     int i, cnt;
     553             :     Encoding *item;
     554             : 
     555           0 :     EncodingInit();
     556             : 
     557           0 :     cnt = 0;
     558           0 :     for ( item=enclist; item!=NULL ; item=item->next )
     559           0 :         if ( !item->hidden )
     560           0 :             ++cnt;
     561           0 :     i = cnt + sizeof(encodingtypes)/sizeof(encodingtypes[0]);
     562           0 :     ti = calloc(i+1,sizeof(GTextInfo));
     563           0 :     memcpy(ti,encodingtypes,sizeof(encodingtypes)-sizeof(encodingtypes[0]));
     564           0 :     for ( i=0; i<sizeof(encodingtypes)/sizeof(encodingtypes[0])-1; ++i ) {
     565           0 :         ti[i].text = (unichar_t *) copy((char *) ti[i].text);
     566             :     }
     567           0 :     if ( cnt!=0 ) {
     568           0 :         ti[i++].line = true;
     569           0 :         for ( item=enclist; item!=NULL ; item=item->next )
     570           0 :             if ( !item->hidden ) {
     571           0 :                 ti[i].text = uc_copy(item->enc_name);
     572           0 :                 ti[i++].userdata = (void *) item->enc_name;
     573             :             }
     574             :     }
     575           0 : return( ti );
     576             : }
     577             : 
     578           0 : GTextInfo *EncodingTypesFindEnc(GTextInfo *encodingtypes, Encoding *enc) {
     579             :     int i;
     580             :     char *name;
     581             :     Encoding *new_enc;
     582             : 
     583           0 :     for ( i=0; encodingtypes[i].text!=NULL || encodingtypes[i].line; ++i ) {
     584           0 :         if ( encodingtypes[i].text==NULL )
     585           0 :     continue;
     586           0 :         name = encodingtypes[i].userdata;
     587           0 :         new_enc = FindOrMakeEncoding(name);
     588           0 :         if ( new_enc==NULL )
     589           0 :     continue;
     590           0 :         if ( enc==new_enc )
     591           0 : return( &encodingtypes[i] );
     592             :     }
     593           0 : return( NULL );
     594             : }
     595             : 
     596           0 : Encoding *ParseEncodingNameFromList(GGadget *listfield) {
     597           0 :     const unichar_t *name = _GGadgetGetTitle(listfield);
     598             :     int32 len;
     599           0 :     GTextInfo **ti = GGadgetGetList(listfield,&len);
     600             :     int i;
     601           0 :     Encoding *enc = NULL;
     602             : 
     603           0 :     for ( i=0; i<len; ++i ) if ( ti[i]->text!=NULL ) {
     604           0 :         if ( u_strcmp(name,ti[i]->text)==0 ) {
     605           0 :             enc = FindOrMakeEncoding(ti[i]->userdata);
     606           0 :     break;
     607             :         }
     608             :     }
     609             : 
     610           0 :     if ( enc == NULL ) {
     611           0 :         char *temp = u2utf8_copy(name);
     612           0 :         enc = FindOrMakeEncoding(temp);
     613           0 :         free(temp);
     614             :     }
     615           0 :     if ( enc==NULL )
     616           0 :         ff_post_error(_("Bad Encoding"),_("Bad Encoding"));
     617           0 : return( enc );
     618             : }

Generated by: LCOV version 1.10