Debian Codegraph @

fontforgeexe/bitmapview.c

raw symbols SCIP
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 <fontforge-config.h>
30
31 #include "bitmapchar.h"
32 #include "bvedit.h"
33 #include "cvundoes.h"
34 #include "encoding.h"
35 #include "fontforgeui.h"
36 #include "fvfonts.h"
37 #include "gkeysym.h"
38 #include "gresedit.h"
39 #include "splinefill.h"
40 #include "splinesaveafm.h"
41 #include "ustring.h"
42 #include "utype.h"
43 #include "bv_mids.h"
44
45 #include <locale.h>
46 #include <math.h>
47
48 int bv_width = 270, bv_height=250;
49
50 extern int _GScrollBar_Width;
51 extern struct lconv localeinfo;
52 extern char *coord_sep;
53 struct bvshows BVShows = { 1, 1, 1, 0 };
54
55 #define RPT_BASE 3 /* Place to draw the pointer icon */
56 #define RPT_DATA 24 /* x,y text after above */
57 #define RPT_COLOR 40 /* Blob showing the foreground color */
58
59 static Color guide_color = 0x404040;
60 static Color width_guide_color = 0x404040;
61 static Color grid_color = 0xa0a0a0;
62 static Color bitmap_color = 0x808080;
63 static Color overview_fg_color = 0x000000;
64 static Color outline_color = 0x00ff00;
65 static Color active_tool_color = 0x909000;
66 static Color ref_color = 0x808080;
67 static Color selection_color = 0x909000;
68 static Color selected_ref_color = 0x909000;
69 static Color ref_border_color = 0x606060;
70 static Color selected_ref_border_color = 0x606000;
71
72 static void BVNewScale(BitmapView *bv) {
73 int fh = bv->bdf->ascent+bv->bdf->descent;
74
75 GScrollBarSetBounds(bv->vsb,-2*fh*bv->scale,4*fh*bv->scale,bv->height);
76 GScrollBarSetBounds(bv->hsb,-3*fh*bv->scale,6*fh*bv->scale,bv->width);
77 GScrollBarSetPos(bv->vsb,bv->yoff);
78 GScrollBarSetPos(bv->hsb,-bv->xoff);
79
80 GDrawRequestExpose(bv->v,NULL,false);
81 }
82
83 static void BVFit(BitmapView *bv) {
84 int left, right, top, bottom, hsc, wsc;
85 int fh = bv->bdf->ascent+bv->bdf->descent;
86 extern int palettes_docked;
87 int offset = palettes_docked ? 80 : 0;
88
89 if ( offset>bv->width ) offset = 0;
90
91 bottom = bv->bc->ymin;
92 top = bv->bc->ymax;
93 left = bv->bc->xmin;
94 right = bv->bc->xmax;
95
96 if ( bottom>0 ) bottom = 0;
97 if ( left>0 ) left = 0;
98 if ( top==-1 && bottom==0 ) { /* Empty */
99 top = bv->bdf->ascent;
100 bottom = -bv->bdf->descent;
101 if ( right==-1 ) right = fh;
102 }
103 if ( top<bottom ) IError("Bottom bigger than top!");
104 if ( right<left ) IError("Left bigger than right!");
105 top -= bottom;
106 right -= left;
107 if ( top==0 ) top = bv->bdf->pixelsize;
108 if ( right==0 ) right = bv->bdf->pixelsize;
109 wsc = (8*(bv->width-offset)) / (10*right);
110 hsc = (8*bv->height) / (10*top);
111 if ( wsc<hsc ) hsc = wsc;
112 if ( hsc<=0 ) hsc = 1;
113 if ( hsc>32 ) hsc = 32;
114
115 bv->scale = hsc;
116
117 bv->xoff = left+(bv->width-offset-right*bv->scale)/2 + offset;
118 bv->yoff = bottom + (bv->height-top*bv->scale)/2;
119 if ( bv->xoff<-3*fh*bv->scale ) bv->xoff = -3*fh*bv->scale;
120 if ( bv->yoff<-2*fh*bv->scale ) bv->yoff = -2*fh*bv->scale;
121
122 BVNewScale(bv);
123 }
124
125 static void BVUnlinkView(BitmapView *bv ) {
126 BitmapView *test;
127
128 if ( bv->bc->views == bv ) {
129 bv->bc->views = bv->next;
130 } else {
131 for ( test=bv->bc->views; test->next!=bv && test->next!=NULL; test=test->next );
132 if ( test->next==bv )
133 test->next = bv->next;
134 }
135 if ( bv->bc->views==NULL ) {
136 /* We just got rid of the last view. Do a little clean up */
137 /* compress the bitmap, and get rid of the floating selection */
138 BCCompressBitmap(bv->bc);
139 BCFlattenFloat(bv->bc);
140 }
141 }
142
143 static void BVRefreshImage(BitmapView *bv) {
144 GRect box;
145
146 box.x = 0; box.width = bv->infoh;
147 box.y = bv->mbh; box.height = bv->infoh;
148 GDrawRequestExpose(bv->gw,&box,false);
149 }
150
151 static void BCCharUpdate(BDFChar *bc) {
152 BitmapView *bv;
153
154 for ( bv = bc->views; bv!=NULL; bv=bv->next ) {
155 GDrawRequestExpose(bv->v, NULL, false );
156 /*BVRefreshImage(bv);*/ /* Select All gives us a blank image if we do this */
157 }
158 }
159
160 static void BC_CharChangedUpdate(BDFChar *bc) {
161 BDFFont *bdf;
162 BitmapView *bv;
163 int waschanged = bc->changed;
164 FontView *fv;
165 struct bdfcharlist *dlist;
166
167 bc->changed = true;
168 for ( bv = bc->views; bv!=NULL; bv=bv->next ) {
169 GDrawRequestExpose(bv->v, NULL, false );
170 BVRefreshImage(bv);
171 }
172
173 fv = (FontView *) (bc->sc->parent->fv);
174 fv->b.sf->changed = true;
175 if ( fv->show!=fv->filled ) {
176 for ( bdf=fv->b.sf->bitmaps; bdf!=NULL && bdf->glyphs[bc->orig_pos]!=bc; bdf=bdf->next );
177 if ( bdf!=NULL ) {
178 FVRefreshChar(fv,bc->orig_pos);
179 if ( fv->b.sf->onlybitmaps && !waschanged )
180 FVToggleCharChanged(fv->b.sf->glyphs[bc->orig_pos]);
181 }
182 }
183 for ( dlist=bc->dependents; dlist!=NULL; dlist=dlist->next )
184 BC_CharChangedUpdate(dlist->bc);
185 }
186
187 static char *BVMakeTitles(BitmapView *bv, BDFChar *bc,char *buf) {
188 char *title;
189 SplineChar *sc;
190 BDFFont *bdf = bv->bdf;
191 char *uniname;
192
193 sc = bc->sc;
194 /* GT: This is the title for a window showing a bitmap character */
195 /* GT: It will look something like: */
196 /* GT: exclam at 33 size 12 from Arial */
197 /* GT: $1 is the name of the glyph */
198 /* GT: $2 is the glyph's encoding */
199 /* GT: $3 is the pixel size of the bitmap font */
200 /* GT: $4 is the font name */
201 sprintf(buf,_("%1$.80s at %2$d size %3$d from %4$.80s"),
202 sc!=NULL ? sc->name : "<Nameless>", bv->enc, bdf->pixelsize, sc==NULL ? "" : sc->parent->fontname);
203 title = copy(buf);
204
205 /* Enhance 'buf' description with Nameslist.txt unicode name definition */
206 if ( (uniname=uniname_name(sc->unicodeenc))!=NULL ) {
207 strcat(buf, " ");
208 strcpy(buf+strlen(buf), uniname);
209 free(uniname);
210 }
211 return( title );
212 }
213
214 void BVChangeBC(BitmapView *bv, BDFChar *bc, int fitit ) {
215 char *title;
216 char buf[300];
217
218 BVUnlinkView(bv);
219 bv->bc = bc;
220 bv->next = bc->views;
221 bc->views = bv;
222
223 if ( fitit )
224 BVFit(bv);
225 else
226 BVNewScale(bv);
227 BVRefreshImage(bv);
228
229 title = BVMakeTitles(bv,bc,buf);
230 GDrawSetWindowTitles8(bv->gw,buf,title);
231 free(title);
232
233 BVPaletteChangedChar(bv);
234 }
235
236 static void BVChangeChar(BitmapView *bv, int i, int fitit ) {
237 BDFChar *bc;
238 BDFFont *bdf = bv->bdf;
239 EncMap *map = bv->fv->b.map;
240
241 if ( bv->fv->b.cidmaster!=NULL && !map->enc->is_compact && i<bdf->glyphcnt &&
242 (bc=bdf->glyphs[i])!=NULL ) {
243 /* The attached bitmap fonts don't have the complexities of subfonts-- they are flat */
244 } else {
245 if ( i<0 || i>=map->enccount )
246 return;
247 bc = BDFMakeChar(bdf,map,i);
248 }
249
250 if ( bc==NULL || bv->bc == bc )
251 return;
252 bv->map_of_enc = map;
253 bv->enc = i;
254
255 BVChangeBC(bv,bc,fitit);
256 }
257
258 static void BVDoClear(BitmapView *bv);
259 static void BVHScroll(BitmapView *bv,struct sbevent *sb);
260 static void BVVScroll(BitmapView *bv,struct sbevent *sb);
261
262 void BVChar(BitmapView *bv, GEvent *event ) {
263 BDFRefChar *head;
264 extern int navigation_mask;
265
266 #if _ModKeysAutoRepeat
267 /* Under cygwin these keys auto repeat, they don't under normal X */
268 if ( bv->autorpt!=NULL ) {
269 GDrawCancelTimer(bv->autorpt); bv->autorpt = NULL;
270 if ( bv->keysym == event->u.chr.keysym ) /* It's an autorepeat, ignore it */
271 return;
272 BVToolsSetCursor(bv,bv->oldstate,NULL);
273 }
274 #endif
275
276 BVPaletteActivate(bv);
277 BVToolsSetCursor(bv,TrueCharState(event),NULL);
278 if ( event->u.chr.keysym=='s' &&
279 (event->u.chr.state&ksm_control) &&
280 (event->u.chr.state&ksm_meta) )
281 MenuSaveAll(NULL,NULL,NULL);
282 else if ( !(event->u.chr.state&(ksm_control|ksm_meta)) &&
283 event->u.chr.keysym == GK_BackSpace ) {
284 /* Menu does delete */
285 BVDoClear(bv);
286 } else if ( event->u.chr.keysym == GK_Help ) {
287 MenuHelp(NULL,NULL,NULL); /* Menu does F1 */
288 } else if ( event->u.chr.keysym == GK_Left ||
289 event->u.chr.keysym == GK_Up ||
290 event->u.chr.keysym == GK_Right ||
291 event->u.chr.keysym == GK_Down ||
292 event->u.chr.keysym == GK_KP_Left ||
293 event->u.chr.keysym == GK_KP_Up ||
294 event->u.chr.keysym == GK_KP_Right ||
295 event->u.chr.keysym == GK_KP_Down ||
296 event->u.chr.keysym == GK_KP_Home ||
297 event->u.chr.keysym == GK_Home ) {
298 int xoff=0, yoff=0;
299 if ( event->u.chr.keysym == GK_Up || event->u.chr.keysym == GK_KP_Up )
300 yoff = 1;
301 else if ( event->u.chr.keysym == GK_Down || event->u.chr.keysym == GK_KP_Down )
302 yoff = -1;
303 else if ( event->u.chr.keysym == GK_Right || event->u.chr.keysym == GK_KP_Right )
304 xoff = 1;
305 else if ( event->u.chr.keysym == GK_Left || event->u.chr.keysym == GK_KP_Left )
306 xoff = -1;
307 else if ( event->u.chr.keysym == GK_Home || event->u.chr.keysym == GK_KP_Home ) {
308 if ( bv->bc->selection==NULL ) {
309 xoff = -bv->bc->xmin;
310 yoff = -bv->bc->ymin;
311 } else {
312 xoff = bv->bc->xmin-bv->bc->selection->xmin;
313 yoff = bv->bc->ymin-bv->bc->selection->ymin;
314 }
315 }
316 if ( event->u.chr.state & (ksm_meta|ksm_control) ) {
317 struct sbevent sb;
318 sb.type = yoff>0 || xoff<0 ? et_sb_halfup : et_sb_halfdown;
319 if ( xoff==0 )
320 BVVScroll(bv,&sb);
321 else
322 BVHScroll(bv,&sb);
323 } else {
324 BCPreserveState(bv->bc);
325 if ( bv->bc->selection==NULL ) {
326 bv->bc->xmin += xoff; bv->bc->xmax += xoff;
327 bv->bc->ymin += yoff; bv->bc->ymax += yoff;
328 for ( head=bv->bc->refs; head!=NULL; head=head->next ) {
329 if ( head->selected ) {
330 head->xoff += xoff;
331 head->yoff += yoff;
332 }
333 }
334 } else {
335 bv->bc->selection->xmin += xoff;
336 bv->bc->selection->xmax += xoff;
337 bv->bc->selection->ymin += yoff;
338 bv->bc->selection->ymax += yoff;
339 }
340 BCCharChangedUpdate(bv->bc);
341 }
342 } else if ( (event->u.chr.state&((GMenuMask()|navigation_mask)&~(ksm_shift|ksm_capslock)))==navigation_mask &&
343 event->type == et_char &&
344 event->u.chr.keysym!=0 &&
345 (event->u.chr.keysym<GK_Special /*|| event->u.chr.keysym>=0x10000*/)) {
346 SplineFont *sf = bv->bc->sc->parent;
347 int i;
348 EncMap *map = bv->fv->b.map;
349 extern int cv_auto_goto;
350 if ( cv_auto_goto ) {
351 i = SFFindSlot(sf,map,event->u.chr.keysym,NULL);
352 if ( i!=-1 )
353 BVChangeChar(bv,i,false);
354 }
355 }
356 }
357
358 static int BVCurEnc(BitmapView *bv) {
359 if ( bv->map_of_enc == bv->fv->b.map && bv->enc!=-1 )
360 return( bv->enc );
361
362 return( bv->fv->b.map->backmap[bv->bc->orig_pos] );
363 }
364
365 static void BVCharUp(BitmapView *bv, GEvent *event ) {
366 if ( event->u.chr.keysym=='I' &&
367 (event->u.chr.state&ksm_shift) &&
368 (event->u.chr.state&ksm_meta) )
369 SCCharInfo(bv->bc->sc,bv->fv->b.active_layer,bv->fv->b.map,BVCurEnc(bv));
370 #if _ModKeysAutoRepeat
371 /* Under cygwin these keys auto repeat, they don't under normal X */
372 else if ( event->u.chr.keysym == GK_Shift_L || event->u.chr.keysym == GK_Shift_R ||
373 event->u.chr.keysym == GK_Control_L || event->u.chr.keysym == GK_Control_R ||
374 event->u.chr.keysym == GK_Meta_L || event->u.chr.keysym == GK_Meta_R ||
375 event->u.chr.keysym == GK_Alt_L || event->u.chr.keysym == GK_Alt_R ||
376 event->u.chr.keysym == GK_Super_L || event->u.chr.keysym == GK_Super_R ||
377 event->u.chr.keysym == GK_Hyper_L || event->u.chr.keysym == GK_Hyper_R ) {
378 if ( bv->autorpt!=NULL ) {
379 GDrawCancelTimer(bv->autorpt);
380 BVToolsSetCursor(bv,bv->oldstate,NULL);
381 }
382 bv->keysym = event->u.chr.keysym;
383 bv->oldstate = TrueCharState(event);
384 bv->autorpt = GDrawRequestTimer(bv->v,100,0,NULL);
385 } else {
386 if ( bv->autorpt!=NULL ) {
387 GDrawCancelTimer(bv->autorpt); bv->autorpt=NULL;
388 BVToolsSetCursor(bv,bv->oldstate,NULL);
389 }
390 BVToolsSetCursor(bv,TrueCharState(event),NULL);
391 }
392 #else
393 BVToolsSetCursor(bv,TrueCharState(event),NULL);
394 #endif
395 }
396
397 /* Used for preview of shapes (line, rectangle, or ellipse) */
398 static void BVDrawTempPoint(BitmapView *bv,int x, int y,void *pixmap) {
399 GRect pixel;
400
401 pixel.width = pixel.height = bv->scale+1;
402 pixel.x = bv->xoff + x*bv->scale;
403 pixel.y = bv->height-bv->yoff-(y+1)*bv->scale;
404 GDrawSetStippled(pixmap,1, 0,0);
405 GDrawFillRect(pixmap,&pixel,active_tool_color);
406 GDrawSetStippled(pixmap,0, 0,0);
407 }
408
409 static void BVDrawRefBorder(BitmapView *bv, BDFChar *bc, GWindow pixmap,
410 uint8_t selected, int8_t xoff, int8_t yoff) {
411 int i, j;
412 int isblack, lw, rw, tw, bw;
413 int tx, ty;
414 Color outcolor = selected ? selected_ref_border_color : ref_border_color;
415
416 for ( i=bc->ymax-bc->ymin; i>=0; --i ) {
417 for ( j=0; j<=bc->xmax-bc->xmin; ++j ) {
418 tx = bv->xoff + (bc->xmin + xoff +j)*bv->scale;
419 ty = bv->height-bv->yoff - (bc->ymax + yoff - i)*bv->scale;
420
421 isblack = ( !bc->byte_data &&
422 ( bc->bitmap[i*bc->bytes_per_line+(j>>3)] & (1<<(7-(j&7))))) ||
423 ( bc->byte_data && bc->bitmap[i*bc->bytes_per_line+j] != 0 );
424 if ( !isblack )
425 continue;
426 lw = ( j == 0 || ( !bc->byte_data &&
427 !( bc->bitmap[i*bc->bytes_per_line+((j-1)>>3)] & (1<<(7-((j-1)&7))))) ||
428 ( bc->byte_data && bc->bitmap[i*bc->bytes_per_line+j-1] == 0 ));
429 rw = ( j == bc->xmax-bc->xmin || ( !bc->byte_data &&
430 !( bc->bitmap[i*bc->bytes_per_line+((j+1)>>3)] & (1<<(7-((j+1)&7))))) ||
431 ( bc->byte_data && bc->bitmap[i*bc->bytes_per_line+j+1] == 0 ));
432 tw = ( i == bc->ymax-bc->ymin || ( !bc->byte_data &&
433 !( bc->bitmap[(i+1)*bc->bytes_per_line+(j>>3)] & (1<<(7-(j&7))))) ||
434 ( bc->byte_data && bc->bitmap[(i+1)*bc->bytes_per_line+j] == 0 ));
435 bw = ( i == 0 || ( !bc->byte_data &&
436 !( bc->bitmap[(i-1)*bc->bytes_per_line+(j>>3)] & (1<<(7-(j&7))))) ||
437 ( bc->byte_data && bc->bitmap[(i-1)*bc->bytes_per_line+j] == 0 ));
438
439 if ( lw )
440 GDrawDrawLine(pixmap,tx+1,ty, tx+1,ty-bv->scale,outcolor);
441 if ( rw )
442 GDrawDrawLine(pixmap,tx+bv->scale-1,ty, tx+bv->scale-1,ty-bv->scale,outcolor);
443 if ( tw )
444 GDrawDrawLine(pixmap,tx,ty-1, tx+bv->scale,ty-1,outcolor);
445 if ( bw )
446 GDrawDrawLine(pixmap,tx,ty-bv->scale+1, tx+bv->scale,ty-bv->scale+1,outcolor);
447 }
448 }
449 }
450
451 static void BVDrawSelection(BitmapView *bv,void *pixmap) {
452 GRect pixel, rect;
453 BDFFloat *sel = bv->bc->selection;
454 GClut *clut = bv->bdf->clut;
455 Color bg = view_bgcol;
456 int i,j;
457
458 /* Draw pixels in selected region */
459 pixel.width = pixel.height = bv->scale+1;
460 for ( i=sel->ymax-sel->ymin; i>=0; --i ) {
461 for ( j=0; j<=sel->xmax-sel->xmin; ++j ) {
462 pixel.x = bv->xoff + (sel->xmin+j)*bv->scale;
463 pixel.y = bv->height-bv->yoff-(sel->ymax-i+1)*bv->scale;
464 if ( clut==NULL ) {
465 if ( sel->bitmap[i*sel->bytes_per_line+(j>>3)] & (1<<(7-(j&7))) ) {
466 GDrawFillRect(pixmap,&pixel,bitmap_color);
467 } else {
468 GDrawFillRect(pixmap,&pixel,bg);
469 }
470 } else
471 GDrawFillRect(pixmap,&pixel,
472 clut->clut[sel->bitmap[i*sel->bytes_per_line+j]]);
473 }
474 }
475
476 /* Draw overlay of selected region */
477 GDrawSetStippled(pixmap,1, 0,0);
478 rect.width = (sel->xmax-sel->xmin+1)*bv->scale;
479 rect.height = (sel->ymax-sel->ymin+1)*bv->scale;
480 rect.x = bv->xoff + sel->xmin*bv->scale;
481 rect.y = bv->height-bv->yoff-(sel->ymax+1)*bv->scale;
482 GDrawFillRect(pixmap,&rect,selection_color);
483 GDrawSetStippled(pixmap,0, 0,0);
484 }
485
486 static void BCBresenhamLine(BitmapView *bv,
487 void (*SetPoint)(BitmapView *,int x, int y, void *data),void *data) {
488 /* Draw a line from (pressed_x,pressed_y) to (info_x,info_y) */
489 /* and call SetPoint for each point */
490 int dx,dy,incr1,incr2,d,x,y,xend;
491 int x1 = bv->pressed_x, y1 = bv->pressed_y;
492 int x2 = bv->info_x, y2 = bv->info_y;
493 int up;
494
495 if ( y2<y1 ) {
496 y2 ^= y1; y1 ^= y2; y2 ^= y1;
497 x2 ^= x1; x1 ^= x2; x2 ^= x1;
498 }
499 dy = y2-y1;
500 if (( dx = x2-x1)<0 ) dx=-dx;
501
502 if ( dy<=dx ) {
503 d = 2*dy-dx;
504 incr1 = 2*dy;
505 incr2 = 2*(dy-dx);
506 if ( x1>x2 ) {
507 x = x2; y = y2;
508 xend = x1;
509 up = -1;
510 } else {
511 x = x1; y = y1;
512 xend = x2;
513 up = 1;
514 }
515 (SetPoint)(bv,x,y,data);
516 while ( x<xend ) {
517 ++x;
518 if ( d<0 ) d+=incr1;
519 else {
520 y += up;
521 d += incr2;
522 }
523 (SetPoint)(bv,x,y,data);
524 }
525 } else {
526 d = 2*dx-dy;
527 incr1 = 2*dx;
528 incr2 = 2*(dx-dy);
529 x = x1; y = y1;
530 if ( x1>x2 ) up = -1; else up = 1;
531 (SetPoint)(bv,x,y,data);
532 while ( y<y2 ) {
533 ++y;
534 if ( d<0 ) d+=incr1;
535 else {
536 x += up;
537 d += incr2;
538 }
539 (SetPoint)(bv,x,y,data);
540 }
541 }
542 }
543
544 static void CirclePoints(BitmapView *bv,int x, int y, int ox, int oy, int xmod, int ymod,
545 void (*SetPoint)(BitmapView *,int x, int y, void *data),void *data) {
546 /* we draw the quadrant between Pi/2 and 0 */
547 if ( bv->active_tool == bvt_filledelipse ) {
548 int j;
549 for ( j=2*oy+ymod-y; j<=y; ++j ) {
550 SetPoint(bv,x,j,data);
551 SetPoint(bv,2*ox+xmod-x,j,data);
552 }
553 } else {
554 SetPoint(bv,x,y,data);
555 SetPoint(bv,x,2*oy+ymod-y,data);
556 SetPoint(bv,2*ox+xmod-x,y,data);
557 SetPoint(bv,2*ox+xmod-x,2*oy+ymod-y,data);
558 }
559 }
560
561 void BCGeneralFunction(BitmapView *bv,
562 void (*SetPoint)(BitmapView *,int x, int y, void *data),void *data) {
563 int i, j;
564 int xmin, xmax, ymin, ymax;
565 int ox, oy, modx, mody;
566 int dx, dy, c,d,dx2,dy2,xp,yp;
567 int x,y;
568
569 if ( bv->pressed_x<bv->info_x ) {
570 xmin = bv->pressed_x; xmax = bv->info_x;
571 } else {
572 xmin = bv->info_x; xmax = bv->pressed_x;
573 }
574 if ( bv->pressed_y<bv->info_y ) {
575 ymin = bv->pressed_y; ymax = bv->info_y;
576 } else {
577 ymin = bv->info_y; ymax = bv->pressed_y;
578 }
579
580 switch ( bv->active_tool ) {
581 case bvt_line:
582 BCBresenhamLine(bv,SetPoint,data);
583 break;
584 case bvt_rect:
585 for ( i=xmin; i<=xmax; ++i ) {
586 SetPoint(bv,i,bv->pressed_y,data);
587 SetPoint(bv,i,bv->info_y,data);
588 }
589 for ( i=ymin; i<=ymax; ++i ) {
590 SetPoint(bv,bv->pressed_x,i,data);
591 SetPoint(bv,bv->info_x,i,data);
592 }
593 break;
594 case bvt_filledrect:
595 for ( i=xmin; i<=xmax; ++i ) {
596 for ( j=ymin; j<=ymax; ++j )
597 SetPoint(bv,i,j,data);
598 }
599 break;
600 case bvt_elipse: case bvt_filledelipse:
601 if ( xmax==xmin || ymax==ymin ) /* degenerate case */
602 BCBresenhamLine(bv,SetPoint,data);
603 else {
604 ox = floor( (xmin+xmax)/2.0 );
605 oy = floor( (ymin+ymax)/2.0 );
606 modx = (xmax+xmin)&1; mody = (ymax+ymin)&1;
607 dx = ox-xmin;
608 dy = oy-ymin;
609 dx2 = dx*dx; dy2 = dy*dy;
610 xp = 0; yp = 4*dy*dx2;
611 c = dy2+(2-4*dy)*dx2; d = 2*dy2 + (1-2*dy)*dx2;
612 x = ox+modx; y = ymax;
613 CirclePoints(bv,x,y,ox,oy,modx,mody,SetPoint,data);
614 while ( x!=xmax ) {
615 #define move_right() (c += 4*dy2+xp, d += 6*dy2+xp, ++x, xp += 4*dy2 )
616 #define move_down() (c += 6*dx2-yp, d += 4*dx2-yp, --y, yp -= 4*dx2 )
617 if ( d<0 || y==0 )
618 move_right();
619 else if ( c > 0 )
620 move_down();
621 else {
622 move_right();
623 move_down();
624 }
625 #undef move_right
626 #undef move_down
627 if ( y<oy ) /* degenerate cases */
628 break;
629 CirclePoints(bv,x,y,ox,oy,modx,mody,SetPoint,data);
630 }
631 if ( bv->active_tool==bvt_elipse ) {
632 /* there may be quite a gap between the two semi-circles */
633 /* because the tangent is nearly vertical here. So just fill */
634 /* it in */
635 int j;
636 for ( j=2*oy+mody-y; j<=y; ++j ) {
637 SetPoint(bv,x,j,data);
638 SetPoint(bv,2*ox+modx-x,j,data);
639 }
640 }
641 }
642 break;
643 }
644 }
645
646 static void BVDrawRefName(BitmapView *bv,GWindow pixmap,BDFRefChar *ref,int fg) {
647 int x,y;
648 GRect size;
649 char *refinfo;
650 IBounds bb;
651
652 refinfo = malloc(strlen(ref->bdfc->sc->name) + 30);
653 sprintf(refinfo,"%s XOff: %d YOff: %d", ref->bdfc->sc->name, ref->xoff, ref->yoff);
654
655 bb.minx = ref->bdfc->xmin + ref->xoff;
656 bb.maxx = ref->bdfc->xmax + ref->xoff;
657 bb.miny = ref->bdfc->ymin + ref->yoff;
658 bb.maxy = ref->bdfc->ymax + ref->yoff;
659 BDFCharQuickBounds(ref->bdfc,&bb,ref->xoff,ref->yoff,false,true);
660 x = bv->xoff + (bb.minx)*bv->scale;
661 y = bv->height - bv->yoff - (bb.maxy + 1)*bv->scale;
662 y -= 5;
663 if ( x<-400 || y<-40 || x>bv->width+400 || y>bv->height )
664 {
665 free(refinfo);
666 return;
667 }
668
669 GDrawLayoutInit(pixmap,refinfo,-1,bv->small);
670 GDrawLayoutExtents(pixmap,&size);
671 GDrawLayoutDraw(pixmap,x-size.width/2,y,fg);
672 free(refinfo);
673 }
674
675 static void BVDrawGlyph(BitmapView *bv, BDFChar *bc, GWindow pixmap, GRect *pixel,
676 uint8_t is_ref, uint8_t selected, int8_t xoff, int8_t yoff) {
677 int i, j;
678 BDFFont *bdf = bv->bdf;
679 BDFRefChar *cur;
680
681 if ( is_ref && !selected )
682 GDrawSetStippled(pixmap,1, 0,0);
683 for ( i=bc->ymax-bc->ymin; i>=0; --i ) {
684 for ( j=0; j<=bc->xmax-bc->xmin; ++j ) {
685 pixel->x = bv->xoff + (bc->xmin + xoff +j)*bv->scale;
686 pixel->y = bv->height-bv->yoff - (bc->ymax + yoff - i + 1)*bv->scale;
687 if ( bdf->clut==NULL ) {
688 if ( bc->bitmap[i*bc->bytes_per_line+(j>>3)] & (1<<(7-(j&7))) ) {
689 GDrawFillRect(pixmap,pixel,is_ref ? ref_color : bitmap_color);
690 if ( selected ) {
691 GDrawSetStippled(pixmap,2, 0,0);
692 GDrawFillRect(pixmap,pixel,selected_ref_color);
693 GDrawSetStippled(pixmap,0, 0,0);
694 }
695 }
696 } else {
697 int index = bc->bitmap[i*bc->bytes_per_line+j];
698 if ( index!=0 ) {
699 GDrawFillRect(pixmap,pixel,bdf->clut->clut[index]);
700 if ( selected ) {
701 GDrawSetStippled(pixmap,2, 0,0);
702 GDrawFillRect(pixmap,pixel,selected_ref_color);
703 GDrawSetStippled(pixmap,0, 0,0);
704 }
705 }
706 }
707 }
708 }
709 if ( is_ref ) {
710 GDrawSetStippled(pixmap,0, 0,0);
711 BVDrawRefBorder( bv,bc,pixmap,selected,xoff,yoff );
712 }
713 for ( cur=bc->refs; cur!=NULL; cur=cur->next ) if ( cur->bdfc != NULL ) {
714 BVDrawGlyph( bv,cur->bdfc,pixmap,pixel,true,(cur->selected | selected),
715 xoff+cur->xoff,yoff+cur->yoff );
716 }
717 }
718
719 static void BVExpose(BitmapView *bv, GWindow pixmap, GEvent *event ) {
720 GRect old;
721 DRect clip;
722 int i;
723 GRect pixel;
724 BDFChar *bc = bv->bc;
725 BDFRefChar *bref;
726 RefChar *refs;
727
728 CharView cvtemp;
729
730 GDrawPushClip(pixmap,&event->u.expose.rect,&old);
731 GDrawSetLineWidth(pixmap,0);
732 if ( bv->showfore ) {
733 /* fore ground is a misnomer. it's what we're interested in but we */
734 /* actually need to draw it first, otherwise it obscures everything */
735 pixel.width = pixel.height = bv->scale+1;
736 BVDrawGlyph( bv,bc,pixmap,&pixel,false,false,0,0 );
737
738 if ( bv->active_tool!=bvt_none ) {
739 /* This does nothing for many tools, but for lines, rects and circles */
740 /* it draws temporary points */
741 BCGeneralFunction(bv,BVDrawTempPoint,pixmap);
742 }
743 /* Selected references are handled in BVDrawGlyph() */
744 if ( bv->bc->selection )
745 BVDrawSelection(bv,pixmap);
746 }
747 if ( bv->showgrid ) {
748 if ( bv->scale>2 ) {
749 for ( i=bv->xoff+bv->scale; i<bv->width; i += bv->scale )
750 GDrawDrawLine(pixmap,i,0, i,bv->height,grid_color);
751 for ( i=bv->xoff-bv->scale; i>0; i -= bv->scale )
752 GDrawDrawLine(pixmap,i,0, i,bv->height,grid_color);
753 for ( i=-bv->yoff+bv->height-bv->scale; i>0; i -= bv->scale )
754 GDrawDrawLine(pixmap,0,i,bv->width,i,grid_color);
755 for ( i=-bv->yoff+bv->height+bv->scale; i<bv->height; i += bv->scale )
756 GDrawDrawLine(pixmap,0,i,bv->width,i,grid_color);
757 }
758 GDrawDrawLine(pixmap,0,-bv->yoff+bv->height-0*bv->scale,bv->width,-bv->yoff+bv->height-0*bv->scale,guide_color);
759 GDrawDrawLine(pixmap,0,-bv->yoff+bv->height-bv->bdf->ascent*bv->scale,
760 bv->width,-bv->yoff+bv->height-bv->bdf->ascent*bv->scale,guide_color);
761 GDrawDrawLine(pixmap,0,-bv->yoff+bv->height+bv->bdf->descent*bv->scale,
762 bv->width,-bv->yoff+bv->height+bv->bdf->descent*bv->scale,guide_color);
763 GDrawDrawLine(pixmap,bv->xoff+0*bv->scale,0, bv->xoff+0*bv->scale,bv->height,guide_color);
764 GDrawDrawLine(pixmap,bv->xoff+bv->bc->width*bv->scale,0, bv->xoff+bv->bc->width*bv->scale,bv->height,width_guide_color);
765 if ( bv->bdf->sf->hasvmetrics )
766 GDrawDrawLine(pixmap,0,-bv->yoff+bv->height-(bv->bdf->ascent-bc->vwidth)*bv->scale,
767 bv->width,-bv->yoff+bv->height-(bv->bdf->ascent-bc->vwidth)*bv->scale,width_guide_color);
768 }
769 if ( bv->showfore ) {
770 /* Reference names are drawn after grid (otherwise some characters may get unreadable */
771 for ( bref=bc->refs; bref!=NULL; bref=bref->next )
772 BVDrawRefName( bv,pixmap,bref,0 );
773 }
774 if ( bv->showoutline ) {
775 memset(&cvtemp,'\0',sizeof(cvtemp));
776 cvtemp.v = bv->v;
777 cvtemp.width = bv->width;
778 cvtemp.height = bv->height;
779
780 cvtemp.cvtabs[0].scale = bv->scscale*bv->scale;
781 cvtemp.cvtabs[0].xoff = bv->xoff/* *bv->scscale*/;
782 cvtemp.cvtabs[0].yoff = bv->yoff/* *bv->scscale*/;
783
784 cvtemp.b.sc = bv->bc->sc;
785 cvtemp.b.drawmode = dm_fore;
786
787 clip.width = event->u.expose.rect.width/cvtemp.cvtabs[0].scale;
788 clip.height = event->u.expose.rect.height/cvtemp.cvtabs[0].scale;
789 clip.x = (event->u.expose.rect.x-cvtemp.cvtabs[0].xoff)/cvtemp.cvtabs[0].scale;
790 clip.y = (cvtemp.height-event->u.expose.rect.y-event->u.expose.rect.height-cvtemp.cvtabs[0].yoff)/cvtemp.cvtabs[0].scale;
791 CVDrawSplineSet(&cvtemp,pixmap,cvtemp.b.sc->layers[ly_fore].splines,outline_color,false,&clip);
792 for ( refs = cvtemp.b.sc->layers[ly_fore].refs; refs!=NULL; refs = refs->next )
793 CVDrawSplineSet(&cvtemp,pixmap,refs->layers[0].splines,outline_color,false,&clip);
794 }
795 if ( bv->active_tool==bvt_pointer ) {
796 if ( bv->bc->selection==NULL ) {
797 /* Draw dashed outline of pending selection region */
798 int xmin, xmax, ymin, ymax;
799 xmin = bv->pressed_x; xmax = bv->info_x;
800 ymin = bv->info_y; ymax = bv->pressed_y;
801 if ( ymin>ymax ) { ymax = ymin; ymin = bv->pressed_y; }
802 if ( xmin>xmax ) { xmin = xmax; xmax = bv->pressed_x; }
803 pixel.width = (xmax-xmin+1) * bv->scale;
804 pixel.height = (ymax-ymin+1) * bv->scale;
805 pixel.x = bv->xoff + xmin*bv->scale;
806 pixel.y = bv->height-bv->yoff-(ymax+1)*bv->scale;
807 GDrawSetDashedLine(pixmap,3,3,0);
808 GDrawDrawRect(pixmap,&pixel,GDrawGetDefaultBackground(NULL));
809 GDrawSetDashedLine(pixmap,3,3,3);
810 GDrawDrawRect(pixmap,&pixel,GDrawGetDefaultForeground(NULL));
811 GDrawSetDashedLine(pixmap,0,0,0);
812 }
813 }
814 GDrawPopClip(pixmap,&old);
815 }
816
817 static void BVInfoDrawText(BitmapView *bv, GWindow pixmap ) {
818 GRect r;
819 Color bg = GDrawGetDefaultBackground(GDrawGetDisplayOfWindow(pixmap));
820 char buffer[50];
821 int ybase = bv->mbh+10+bv->sas;
822
823 GDrawSetFont(pixmap,bv->small);
824 r.x = bv->infoh+RPT_DATA; r.width = 39;
825 r.y = bv->mbh; r.height = 36 /* bv->infoh-1 */;
826 GDrawFillRect(pixmap,&r,bg);
827
828 sprintf(buffer,"%d%s%d", bv->info_x, coord_sep, bv->info_y );
829 buffer[11] = '\0';
830 GDrawDrawText8(pixmap,bv->infoh+RPT_DATA,ybase,buffer,-1,GDrawGetDefaultForeground(NULL));
831
832 if ( bv->active_tool!=cvt_none ) {
833 sprintf(buffer,"%d%s%d", bv->info_x-bv->pressed_x, coord_sep, bv->info_y-bv->pressed_y );
834 buffer[11] = '\0';
835 GDrawDrawText8(pixmap,bv->infoh+RPT_DATA,ybase+bv->sfh+10,buffer,-1,GDrawGetDefaultForeground(NULL));
836 }
837 }
838
839 static void BVMainExpose(BitmapView *bv, GWindow pixmap, GEvent *event ) {
840 GRect old, temp, box, old2, r;
841 GImage gi;
842 struct _GImage base;
843 GClut clut;
844 BDFChar *bdfc = BDFGetMergedChar( bv->bc );
845
846 temp = event->u.expose.rect;
847 if ( temp.y+temp.height < bv->mbh )
848 return;
849 if ( temp.y <bv->mbh ) {
850 temp.height -= (bv->mbh-temp.y);
851 temp.y = bv->mbh;
852 }
853 GDrawPushClip(pixmap,&temp,&old);
854 GDrawSetLineWidth(pixmap,0);
855
856 if ( event->u.expose.rect.x<6+bdfc->xmax-bdfc->xmin ) {
857 box.x = 0; box.width = bv->infoh;
858 box.y = bv->mbh; box.height = bv->infoh;
859 GDrawPushClip(pixmap,&box,&old2);
860
861 memset(&gi,'\0',sizeof(gi));
862 memset(&base,'\0',sizeof(base));
863 memset(&clut,'\0',sizeof(clut));
864 gi.u.image = &base;
865 if ( bv->bdf->clut==NULL ) {
866 base.image_type = it_mono;
867 base.clut = &clut;
868 clut.clut_len = 2;
869 clut.clut[0] = GDrawGetDefaultBackground(NULL);
870 clut.clut[1] = overview_fg_color;
871 } else {
872 base.image_type = it_index;
873 base.clut = bv->bdf->clut;
874 }
875 base.data = bdfc->bitmap;
876 base.bytes_per_line = bdfc->bytes_per_line;
877 base.width = bdfc->xmax-bdfc->xmin+1;
878 base.height = bdfc->ymax-bdfc->ymin+1;
879 GDrawDrawImage(pixmap,&gi,NULL, 5,bv->mbh+(bv->infoh-base.height)/2);
880
881 GDrawPopClip(pixmap,&old2);
882 }
883 if (event->u.expose.rect.y < bv->mbh + bv->infoh - 1) {
884 GDrawDrawImage(pixmap,&GIcon_rightpointer,NULL,bv->infoh+RPT_BASE,bv->mbh+8);
885 GDrawDrawImage(pixmap,&GIcon_press2ptr,NULL,bv->infoh+RPT_BASE,bv->mbh+18+bv->sfh);
886 BVInfoDrawText(bv,pixmap );
887
888 r.x = bv->infoh+RPT_DATA; r.y = bv->mbh+36;
889 r.width = 20; r.height = 10;
890 GDrawFillRect(pixmap,&r,
891 bv->bdf->clut==NULL ? GDrawGetDefaultBackground(NULL) :
892 bv->bdf->clut->clut[bv->color/( 255/((1<<BDFDepth(bv->bdf))-1) )] );
893
894 GDrawDrawImage(pixmap,&GIcon_press2ptr,NULL,bv->infoh+RPT_BASE,bv->mbh+18+bv->sfh);
895 }
896 GDrawDrawLine(pixmap,0,bv->mbh+bv->infoh-1,bv->width+300,bv->mbh+bv->infoh-1,GDrawGetDefaultForeground(NULL));
897
898 r.x = bv->width; r.y = bv->height+bv->infoh+bv->mbh;
899 LogoExpose(pixmap,event,&r,dm_fore);
900
901 GDrawPopClip(pixmap,&old);
902 BDFCharFree( bdfc );
903 }
904
905 static void BVShowInfo(BitmapView *bv) {
906 GRect r;
907 r.x = bv->infoh+RPT_DATA; r.width = 39;
908 r.y = bv->mbh; r.height = 36 /* bv->infoh-1 */;
909 GDrawRequestExpose(bv->gw, &r, false);
910 }
911
912 static void BVResize(BitmapView *bv, GEvent *event ) {
913 int sbsize = GDrawPointsToPixels(bv->gw,_GScrollBar_Width);
914 int newwidth = event->u.resize.size.width-sbsize,
915 newheight = event->u.resize.size.height-sbsize - bv->mbh-bv->infoh;
916 GRect size;
917
918 if ( newwidth == bv->width && newheight == bv->height )
919 return;
920
921 /* MenuBar takes care of itself */
922 GDrawResize(bv->v,newwidth,newheight);
923 GGadgetMove(bv->vsb,newwidth, bv->mbh+bv->infoh);
924 GGadgetResize(bv->vsb,sbsize,newheight);
925 GGadgetMove(bv->hsb,0,event->u.resize.size.height-sbsize);
926 GGadgetResize(bv->hsb,newwidth,sbsize);
927 bv->width = newwidth; bv->height = newheight;
928 GGadgetGetSize(bv->recalc,&size);
929 GGadgetMove(bv->recalc,event->u.resize.size.width - size.width - GDrawPointsToPixels(bv->gw,6),size.y);
930 GDrawRequestExpose(bv->gw,NULL,false);
931 BVFit(bv);
932
933 bv_width = event->u.resize.size.width;
934 bv_height = event->u.resize.size.height;
935 SavePrefs(true);
936 }
937
938 static void BVHScroll(BitmapView *bv,struct sbevent *sb) {
939 int newpos = bv->xoff;
940 int fh = bv->bdf->ascent+bv->bdf->descent;
941
942 switch( sb->type ) {
943 case et_sb_top:
944 newpos = 0;
945 break;
946 case et_sb_uppage:
947 newpos += 9*bv->width/10;
948 break;
949 case et_sb_up:
950 newpos += bv->width/15;
951 break;
952 case et_sb_down:
953 newpos -= bv->width/15;
954 break;
955 case et_sb_downpage:
956 newpos -= 9*bv->width/10;
957 break;
958 case et_sb_bottom:
959 newpos = 0;
960 break;
961 case et_sb_thumb:
962 case et_sb_thumbrelease:
963 newpos = -sb->pos;
964 break;
965 case et_sb_halfup:
966 newpos += bv->width/30;
967 break;
968 case et_sb_halfdown:
969 newpos -= bv->width/30;
970 break;
971 }
972 if ( newpos>6*fh*bv->scale-bv->width )
973 newpos = 6*fh*bv->scale-bv->width;
974 if ( newpos<-3*fh*bv->scale ) newpos = -3*fh*bv->scale;
975 if ( newpos!=bv->xoff ) {
976 int diff = newpos-bv->xoff;
977 bv->xoff = newpos;
978 GScrollBarSetPos(bv->hsb,-newpos);
979 GDrawScroll(bv->v,NULL,diff,0);
980 }
981 }
982
983 static void BVVScroll(BitmapView *bv,struct sbevent *sb) {
984 int newpos = bv->yoff;
985 int fh = bv->bdf->ascent+bv->bdf->descent;
986
987 switch( sb->type ) {
988 case et_sb_top:
989 newpos = 0;
990 break;
991 case et_sb_uppage:
992 newpos -= 9*bv->width/10;
993 break;
994 case et_sb_up:
995 newpos -= bv->width/15;
996 break;
997 case et_sb_down:
998 newpos += bv->width/15;
999 break;
1000 case et_sb_downpage:
1001 newpos += 9*bv->width/10;
1002 break;
1003 case et_sb_bottom:
1004 newpos = 0;
1005 break;
1006 case et_sb_thumb:
1007 case et_sb_thumbrelease:
1008 newpos = sb->pos;
1009 break;
1010 case et_sb_halfup:
1011 newpos -= bv->width/30;
1012 break;
1013 case et_sb_halfdown:
1014 newpos += bv->width/30;
1015 break;
1016 }
1017 if ( newpos>4*fh*bv->scale-bv->height )
1018 newpos = 4*fh*bv->scale-bv->height;
1019 if ( newpos<-2*fh*bv->scale ) newpos = -2*fh*bv->scale;
1020 if ( newpos!=bv->yoff ) {
1021 int diff = newpos-bv->yoff;
1022 bv->yoff = newpos;
1023 GScrollBarSetPos(bv->vsb,newpos);
1024 GDrawScroll(bv->v,NULL,0,diff);
1025 }
1026 }
1027
1028 static int BVRecalc(GGadget *g, GEvent *e) {
1029 BitmapView *bv;
1030 BDFChar *bdfc;
1031 void *freetypecontext=NULL;
1032
1033 if ( e->type==et_controlevent && e->u.control.subtype == et_buttonactivate ) {
1034 bv = GDrawGetUserData(GGadgetGetWindow(g));
1035 BCPreserveState(bv->bc);
1036 BCFlattenFloat(bv->bc);
1037 freetypecontext = FreeTypeFontContext(bv->bc->sc->parent,bv->bc->sc,NULL,ly_fore);
1038 if ( freetypecontext!=NULL ) {
1039 bdfc = SplineCharFreeTypeRasterize(freetypecontext,bv->bc->sc->orig_pos,bv->bdf->pixelsize,72,BDFDepth(bv->bdf));
1040 FreeTypeFreeContext(freetypecontext);
1041 } else
1042 bdfc = SplineCharAntiAlias(bv->bc->sc,ly_fore,bv->bdf->pixelsize,(1<<(BDFDepth(bv->bdf)/2)));
1043 free(bv->bc->bitmap);
1044 bv->bc->bitmap = bdfc->bitmap; bdfc->bitmap = NULL;
1045 bv->bc->width = bdfc->width;
1046 bv->bc->xmin = bdfc->xmin;
1047 bv->bc->xmax = bdfc->xmax;
1048 bv->bc->ymin = bdfc->ymin;
1049 bv->bc->ymax = bdfc->ymax;
1050 bv->bc->bytes_per_line = bdfc->bytes_per_line;
1051 BDFCharFree(bdfc);
1052 BCCharChangedUpdate(bv->bc);
1053 }
1054 return( true );
1055 }
1056
1057 static void BVSetWidth(BitmapView *bv, int x) {
1058 int tot, cnt;
1059 BDFFont *bdf;
1060 BDFChar *bc = bv->bc;
1061
1062 bc->width = x;
1063 if ( bv->bdf->sf->onlybitmaps ) {
1064 tot=0; cnt=0;
1065 for ( bdf = bv->bdf->sf->bitmaps; bdf!=NULL; bdf=bdf->next )
1066 if ( bdf->glyphs[bc->orig_pos]) {
1067 tot += bdf->glyphs[bc->orig_pos]->width*1000/(bdf->ascent+bdf->descent);
1068 ++cnt;
1069 }
1070 if ( cnt!=0 ) {
1071 bc->sc->width = tot/cnt;
1072 bc->sc->widthset = true;
1073 }
1074 }
1075 BCCharChangedUpdate(bc);
1076 }
1077
1078 static void BVSetVWidth(BitmapView *bv, int y) {
1079 int tot, cnt;
1080 BDFFont *bdf;
1081 BDFChar *bc = bv->bc;
1082
1083 if ( !bv->bdf->sf->hasvmetrics )
1084 return;
1085 bc->vwidth = bv->bdf->ascent-y;
1086 if ( bv->bdf->sf->onlybitmaps ) {
1087 tot=0; cnt=0;
1088 for ( bdf = bv->bdf->sf->bitmaps; bdf!=NULL; bdf=bdf->next )
1089 if ( bdf->glyphs[bc->orig_pos]) {
1090 tot += bdf->glyphs[bc->orig_pos]->vwidth*1000/(bdf->ascent+bdf->descent);
1091 ++cnt;
1092 }
1093 if ( cnt!=0 && bv->bdf->sf->onlybitmaps ) {
1094 bc->sc->vwidth = tot/cnt;
1095 bc->sc->widthset = true;
1096 }
1097 }
1098 BCCharChangedUpdate(bc);
1099 }
1100
1101 int BVColor(BitmapView *bv) {
1102 int div = 255/((1<<BDFDepth(bv->bdf))-1);
1103 return ( (bv->color+div/2)/div );
1104 }
1105
1106 static int IsReferenceTouched(BitmapView *bv, BDFRefChar *ref, int x, int y){
1107 BDFRefChar *head;
1108 BDFChar *rbc;
1109 int nx, ny;
1110
1111 if ( ref == NULL )
1112 return( false );
1113
1114 rbc = ref->bdfc;
1115 ny = rbc->ymax - y + ref->yoff;
1116 nx = x - rbc->xmin - ref->xoff;
1117 if (nx>=0 && nx<=( rbc->xmax - rbc->xmin ) &&
1118 ny>=0 && ny<=( rbc->ymax - rbc->ymin ) &&
1119 (( rbc->byte_data && rbc->bitmap[ny*rbc->bytes_per_line+nx] != 0 ) ||
1120 (( !rbc->byte_data &&
1121 rbc->bitmap[ny*rbc->bytes_per_line + (nx>>3)] & (1<<(7 - (nx&7)))))))
1122 return( true );
1123
1124 for ( head = rbc->refs; head != NULL; head = head->next ) {
1125 if ( IsReferenceTouched( bv,head,x,y))
1126 return( true );
1127 }
1128 return( false );
1129 }
1130
1131 static void BVMouseDown(BitmapView *bv, GEvent *event) {
1132 int x = floor( (event->u.mouse.x-bv->xoff)/ (real) bv->scale);
1133 int y = floor( (bv->height-event->u.mouse.y-bv->yoff)/ (real) bv->scale);
1134 int ny;
1135 BDFChar *bc = bv->bc;
1136 BDFFloat *sel;
1137 int color_under_cursor;
1138 BDFRefChar *refsel = NULL, *head;
1139
1140 if ( event->u.mouse.button==2 && event->u.mouse.device!=NULL &&
1141 strcmp(event->u.mouse.device,"stylus")==0 )
1142 return; /* I treat this more like a modifier key change than a button press */
1143
1144 if ( event->u.mouse.button==3 ) {
1145 BVToolsPopup(bv,event);
1146 return;
1147 }
1148 BVToolsSetCursor(bv,event->u.mouse.state|(1<<(7+event->u.mouse.button)), event->u.mouse.device );
1149 bv->active_tool = bv->showing_tool;
1150 bv->pressed_x = x; bv->pressed_y = y;
1151 bv->info_x = x; bv->info_y = y;
1152 ny = bc->ymax-y;
1153 if ( x<bc->xmin || x>bc->xmax || ny<0 || ny>bc->ymax-bc->ymin )
1154 color_under_cursor = 0;
1155 else if ( bc->byte_data )
1156 color_under_cursor = bc->bitmap[(bc->ymax-y)*bc->bytes_per_line + x-bc->xmin] *
1157 255/((1<<BDFDepth(bv->bdf))-1);
1158 else
1159 color_under_cursor = bc->bitmap[(bc->ymax-y)*bc->bytes_per_line + (x-bc->xmin)/8]&(0x80>>((x-bc->xmin)&7)) *
1160 255;
1161 BVPaletteColorUnderChange(bv,color_under_cursor);
1162 bv->event_x = event->u.mouse.x; bv->event_y = event->u.mouse.y;
1163 bv->recentchange = false;
1164 for ( head = bc->refs; head != NULL; head = head->next ) {
1165 if ( IsReferenceTouched( bv,head,x,y ))
1166 refsel = head;
1167 }
1168 switch ( bv->active_tool ) {
1169 case bvt_eyedropper:
1170 bv->color = color_under_cursor;
1171 /* Store color as a number between 0 and 255 no matter what the clut size is */
1172 BVPaletteColorChange(bv);
1173 break;
1174 case bvt_pencil: case bvt_line:
1175 case bvt_rect: case bvt_filledrect:
1176 ny = bc->ymax-y;
1177 bv->clearing = false;
1178 if ( !bc->byte_data && x>=bc->xmin && x<=bc->xmax &&
1179 ny>=0 && ny<=bc->ymax-bc->ymin ) {
1180 int nx = x-bc->xmin;
1181 if ( bc->bitmap[ny*bc->bytes_per_line + (nx>>3)] &
1182 (1<<(7-(nx&7))) )
1183 bv->clearing = true;
1184 }
1185 BCPreserveState(bc);
1186 BCFlattenFloat(bc);
1187 if ( bv->active_tool == bvt_pencil )
1188 BCSetPoint(bc,x,y,bc->byte_data?BVColor(bv):!bv->clearing);
1189 BCCharChangedUpdate(bc);
1190 break;
1191 case bvt_elipse: case bvt_filledelipse:
1192 BCPreserveState(bc);
1193 BCFlattenFloat(bc);
1194 BCCharChangedUpdate(bc);
1195 break;
1196 case bvt_pointer:
1197 if ( !( event->u.mouse.state&ksm_shift )) {
1198 for ( head = bc->refs; head != NULL; head=head->next )
1199 head->selected = false;
1200 }
1201 if ( refsel != NULL ) {
1202 BCFlattenFloat(bc);
1203 refsel->selected = ( event->u.mouse.state&ksm_shift ) ?
1204 !(refsel->selected) : true;
1205 GDrawSetCursor(bv->v,ct_shift);
1206 } else if ( (sel = bc->selection)!=NULL ) {
1207 if ( x<sel->xmin || x>sel->xmax || y<sel->ymin || y>sel->ymax )
1208 BCFlattenFloat(bc);
1209 else {
1210 GDrawSetCursor(bv->v,ct_shift);
1211 /* otherwise we'll move the selection */
1212 }
1213 } else if ( /*bc->sc->parent->onlybitmaps &&*/
1214 event->u.mouse.x-bv->xoff > bc->width*bv->scale-3 &&
1215 event->u.mouse.x-bv->xoff < bc->width*bv->scale+3 ) {
1216 bv->active_tool = bvt_setwidth;
1217 BVToolsSetCursor(bv,event->u.mouse.state|(1<<(7+event->u.mouse.button)), event->u.mouse.device );
1218 } else if ( /*bc->sc->parent->onlybitmaps &&*/ bc->sc->parent->hasvmetrics &&
1219 bv->height-event->u.mouse.y-bv->yoff > (bv->bdf->ascent-bc->vwidth)*bv->scale-3 &&
1220 bv->height-event->u.mouse.y-bv->yoff < (bv->bdf->ascent-bc->vwidth)*bv->scale+3 ) {
1221 bv->active_tool = bvt_setvwidth;
1222 BVToolsSetCursor(bv,event->u.mouse.state|(1<<(7+event->u.mouse.button)), event->u.mouse.device );
1223 }
1224 BCCharUpdate(bc);
1225 break;
1226 case bvt_setwidth:
1227 BVSetWidth(bv,x);
1228 break;
1229 case bvt_setvwidth:
1230 BVSetVWidth(bv,y);
1231 break;
1232 }
1233 }
1234
1235 static void BVMouseMove(BitmapView *bv, GEvent *event) {
1236 int x = floor( (event->u.mouse.x-bv->xoff)/ (real) bv->scale);
1237 int y = floor( (bv->height-event->u.mouse.y-bv->yoff)/ (real) bv->scale);
1238 int newx, newy;
1239 int fh = bv->bdf->ascent+bv->bdf->descent;
1240 BDFChar *bc = bv->bc;
1241 int color_under_cursor, ny, has_selected_refs = false;
1242 BDFRefChar *head;
1243
1244 bv->info_x = x; bv->info_y = y;
1245 ny = bc->ymax-y;
1246 if ( x<bc->xmin || x>bc->xmax || ny<0 || ny>bc->ymax-bc->ymin )
1247 color_under_cursor = 0;
1248 else if ( bc->byte_data )
1249 color_under_cursor = bc->bitmap[(bc->ymax-y)*bc->bytes_per_line + x-bc->xmin] *
1250 255/((1<<BDFDepth(bv->bdf))-1);
1251 else
1252 color_under_cursor = bc->bitmap[(bc->ymax-y)*bc->bytes_per_line + (x-bc->xmin)/8]&(0x80>>((x-bc->xmin)&7)) *
1253 255;
1254 BVShowInfo(bv);
1255 BVPaletteColorUnderChange(bv,color_under_cursor);
1256 if ( bv->active_tool==bvt_none )
1257 return; /* Not pressed */
1258 switch ( bv->active_tool ) {
1259 case bvt_pencil:
1260 BCSetPoint(bc,x,y,bc->byte_data?BVColor(bv):!bv->clearing);
1261 BCCharChangedUpdate(bc);
1262 break;
1263 case bvt_line: case bvt_rect: case bvt_filledrect:
1264 case bvt_elipse: case bvt_filledelipse:
1265 BCCharChangedUpdate(bc);
1266 break;
1267 case bvt_hand:
1268 newx = bv->xoff + event->u.mouse.x-bv->event_x;
1269 newy = bv->yoff + bv->event_y-event->u.mouse.y;
1270 if ( newy>4*fh*bv->scale-bv->height )
1271 newy = 4*fh*bv->scale-bv->height;
1272 if ( newy<-2*fh*bv->scale ) newy = -2*fh*bv->scale;
1273 if ( newx>6*fh*bv->scale-bv->width )
1274 newx = 6*fh*bv->scale-bv->width;
1275 if ( newx<-3*fh*bv->scale ) newx = -3*fh*bv->scale;
1276 if ( newx!=bv->xoff || newy!=bv->yoff ) {
1277 newx -= bv->xoff; bv->xoff += newx;
1278 newy -= bv->yoff; bv->yoff += newy;
1279 GScrollBarSetPos(bv->hsb,-bv->xoff);
1280 GScrollBarSetPos(bv->vsb,-bv->yoff);
1281 GDrawScroll(bv->v,NULL,newx,newy);
1282 }
1283 bv->event_x = event->u.mouse.x; bv->event_y = event->u.mouse.y;
1284 break;
1285 case bvt_shift:
1286 if ( x!=bv->pressed_x || y!=bv->pressed_y ) {
1287 if ( !bv->recentchange ) {
1288 BCPreserveState(bc);
1289 BCFlattenFloat(bc);
1290 bv->recentchange = true;
1291 }
1292 bc->xmin += x-bv->pressed_x;
1293 bc->xmax += x-bv->pressed_x;
1294 bc->ymin += y-bv->pressed_y;
1295 bc->ymax += y-bv->pressed_y;
1296
1297 for ( head=bc->refs; head!=NULL; head=head->next ) {
1298 if ( head->selected ) {
1299 head->xoff += x-bv->pressed_x;
1300 head->yoff += y-bv->pressed_y;
1301 }
1302 }
1303 BCCharChangedUpdate(bc);
1304 bv->pressed_x = x; bv->pressed_y = y;
1305 }
1306 break;
1307 case bvt_pointer:
1308 for ( head=bc->refs; head!=NULL && !has_selected_refs; head=head->next ) {
1309 if ( head->selected ) has_selected_refs = true;
1310 }
1311 if ( bc->selection!=NULL || has_selected_refs ) {
1312 if ( x!=bv->pressed_x || y!=bv->pressed_y ) {
1313 if ( !bv->recentchange ) {
1314 BCPreserveState(bc);
1315 bv->recentchange = true;
1316 }
1317 if ( has_selected_refs ) {
1318 for ( head=bc->refs; head!=NULL; head=head->next ) {
1319 if ( head->selected ) {
1320 head->xoff += x-bv->pressed_x;
1321 head->yoff += y-bv->pressed_y;
1322 }
1323 }
1324 } else if ( bc->selection != NULL ) {
1325 bc->selection->xmin += x-bv->pressed_x;
1326 bc->selection->xmax += x-bv->pressed_x;
1327 bc->selection->ymin += y-bv->pressed_y;
1328 bc->selection->ymax += y-bv->pressed_y;
1329 }
1330 BCCharChangedUpdate(bc);
1331 bv->pressed_x = x; bv->pressed_y = y;
1332 }
1333 } else {
1334 GDrawRequestExpose(bv->v,NULL,false);
1335 }
1336 break;
1337 case bvt_setwidth:
1338 BVSetWidth(bv,x);
1339 break;
1340 case bvt_setvwidth:
1341 BVSetVWidth(bv,y);
1342 break;
1343 }
1344 }
1345
1346 static void BVSetPoint(BitmapView *bv, int x, int y, void *junk) {
1347 BCSetPoint(bv->bc,x,y,bv->bc->byte_data?BVColor(bv):!bv->clearing);
1348 }
1349
1350 static void BVMagnify(BitmapView *bv, int midx, int midy, int bigger);
1351
1352 static void BVMouseUp(BitmapView *bv, GEvent *event) {
1353 int x = floor( (event->u.mouse.x-bv->xoff)/ (real) bv->scale);
1354 int y = floor( (bv->height-event->u.mouse.y-bv->yoff)/ (real) bv->scale);
1355 BDFRefChar *refsel = NULL, *head;
1356
1357 BVMouseMove(bv,event);
1358 for ( head = bv->bc->refs; head != NULL; head = head->next ) {
1359 if ( IsReferenceTouched( bv,head,x,y ))
1360 refsel = head;
1361 }
1362 switch ( bv->active_tool ) {
1363 case bvt_magnify: case bvt_minify:
1364 BVMagnify(bv,x,y,bv->active_tool==bvt_magnify?1:-1);
1365 break;
1366 case bvt_line: case bvt_rect: case bvt_filledrect:
1367 case bvt_elipse: case bvt_filledelipse:
1368 if ( refsel == NULL ) {
1369 BCGeneralFunction(bv,BVSetPoint,NULL);
1370 bv->active_tool = bvt_none;
1371 BCCharChangedUpdate(bv->bc);
1372 }
1373 break;
1374 case bvt_pointer:
1375 if ( bv->bc->selection!=NULL ) {
1376 /* we've been moving it */
1377 GDrawSetCursor(bv->v,ct_mypointer);
1378 if ( !bv->recentchange ) { /* Oh, we just clicked in it, get rid of it */
1379 BCFlattenFloat(bv->bc);
1380 BCCharChangedUpdate(bv->bc);
1381 }
1382 } else if ( refsel ) {
1383 GDrawSetCursor(bv->v,ct_mypointer);
1384 bv->active_tool = bvt_none;
1385 BCCharChangedUpdate(bv->bc);
1386 } else {
1387 int dx,dy;
1388 if ( (dx = event->u.mouse.x-bv->event_x)<0 ) dx = -dx;
1389 if ( (dy = event->u.mouse.y-bv->event_y)<0 ) dy = -dy;
1390 if ( dx+dy>4 ) {
1391 /* we've just dragged out a new one */
1392 BDFFloatCreate(bv->bc,bv->pressed_x,bv->info_x,bv->pressed_y,bv->info_y,true);
1393 }
1394 bv->active_tool = bvt_none;
1395 BCCharChangedUpdate(bv->bc);
1396 }
1397 break;
1398 case bvt_setwidth:
1399 BVSetWidth(bv,x);
1400 break;
1401 case bvt_setvwidth:
1402 BVSetVWidth(bv,y);
1403 break;
1404 }
1405 bv->active_tool = bvt_none;
1406 BVToolsSetCursor(bv,event->u.mouse.state&~(1<<(7+event->u.mouse.button)), event->u.mouse.device); /* X still has the buttons set in the state, even though we just released them. I don't want em */
1407 }
1408
1409 static int v_e_h(GWindow gw, GEvent *event) {
1410 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1411
1412 if (( event->type==et_mouseup || event->type==et_mousedown ) &&
1413 (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) {
1414 int ish = event->u.mouse.button>5;
1415 if ( event->u.mouse.state&ksm_shift ) ish = !ish;
1416 if ( ish ) /* bind shift to vertical scrolling */
1417 return( GGadgetDispatchEvent(bv->hsb,event));
1418 else
1419 return( GGadgetDispatchEvent(bv->vsb,event));
1420 }
1421
1422 switch ( event->type ) {
1423 case et_selclear:
1424 ClipboardClear();
1425 break;
1426 case et_expose:
1427 GDrawSetLineWidth(gw,0);
1428 BVExpose(bv,gw,event);
1429 break;
1430 case et_crossing:
1431 BVToolsSetCursor(bv,event->u.mouse.state, event->u.mouse.device);
1432 break;
1433 case et_mousedown:
1434 BVPaletteActivate(bv);
1435 BVMouseDown(bv,event);
1436 break;
1437 case et_mousemove:
1438 BVMouseMove(bv,event);
1439 break;
1440 case et_mouseup:
1441 BVMouseUp(bv,event);
1442 break;
1443 case et_char:
1444 BVChar(bv,event);
1445 break;
1446 case et_charup:
1447 BVCharUp(bv,event);
1448 break;
1449 case et_timer:
1450 #if _ModKeysAutoRepeat
1451 /* Under cygwin the modifier keys auto repeat, they don't under normal X */
1452 if ( bv->autorpt==event->u.timer.timer ) {
1453 bv->autorpt = NULL;
1454 BVToolsSetCursor(bv,bv->oldstate,NULL);
1455 }
1456 #endif
1457 break;
1458 case et_focus:
1459 break;
1460 default:
1461 break;
1462 }
1463 return( true );
1464 }
1465
1466 static int bv_e_h(GWindow gw, GEvent *event) {
1467 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1468 int enc;
1469
1470 if (( event->type==et_mouseup || event->type==et_mousedown ) &&
1471 (event->u.mouse.button>=4 && event->u.mouse.button<=7) ) {
1472 int ish = event->u.mouse.button>5;
1473 if ( event->u.mouse.state&ksm_shift ) ish = !ish;
1474 if ( ish ) /* bind shift to vertical scrolling */
1475 return( GGadgetDispatchEvent(bv->hsb,event));
1476 else
1477 return( GGadgetDispatchEvent(bv->vsb,event));
1478 }
1479
1480 switch ( event->type ) {
1481 case et_expose:
1482 GDrawSetLineWidth(gw,0);
1483 BVMainExpose(bv,gw,event);
1484 break;
1485 case et_char:
1486 BVChar(bv,event);
1487 break;
1488 case et_charup:
1489 BVCharUp(bv,event);
1490 break;
1491 case et_resize:
1492 if ( event->u.resize.sized )
1493 BVResize(bv,event);
1494 break;
1495 case et_controlevent:
1496 switch ( event->u.control.subtype ) {
1497 case et_scrollbarchange:
1498 if ( event->u.control.g == bv->hsb )
1499 BVHScroll(bv,&event->u.control.u.sb);
1500 else
1501 BVVScroll(bv,&event->u.control.u.sb);
1502 break;
1503 default: break;
1504 }
1505 break;
1506 case et_destroy:
1507 BVUnlinkView(bv);
1508 BVPalettesHideIfMine(bv);
1509 BitmapViewFree(bv);
1510 break;
1511 case et_map:
1512 if ( event->u.map.is_visible )
1513 BVPaletteActivate(bv);
1514 else
1515 BVPalettesHideIfMine(bv);
1516 break;
1517 case et_close:
1518 GDrawDestroyWindow(gw);
1519 break;
1520 case et_mouseup: case et_mousedown:
1521 GGadgetEndPopup();
1522 BVPaletteActivate(bv);
1523 break;
1524 case et_mousemove:
1525 enc = BVCurEnc(bv);
1526 SCPreparePopup(bv->gw,bv->bc->sc,bv->fv->b.map->remap,enc,
1527 UniFromEnc(enc,bv->fv->b.map->enc));
1528 break;
1529 case et_focus:
1530 break;
1531 default: break;
1532 }
1533 return( true );
1534 }
1535
1536 static void BVMenuOpen(GWindow gw, struct gmenuitem *mi, GEvent *g) {
1537 BitmapView *d = (BitmapView*)GDrawGetUserData(gw);
1538 FontView *fv = NULL;
1539 if (d) {
1540 fv = (FontView*)d->fv;
1541 }
1542 _FVMenuOpen(fv);
1543 }
1544
1545 static void BVMenuClose(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1546 GDrawDestroyWindow(gw);
1547 }
1548
1549 static void BVMenuOpenOutline(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1550 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1551
1552 CharViewCreate(bv->bc->sc,bv->fv,bv->map_of_enc==bv->fv->b.map?bv->enc:-1);
1553 }
1554
1555 static void BVMenuOpenMetrics(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1556 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1557 MetricsViewCreate(bv->fv,bv->bc->sc,bv->bdf);
1558 }
1559
1560 static void BVMenuSave(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1561 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1562 _FVMenuSave(bv->fv);
1563 }
1564
1565 static void BVMenuSaveAs(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1566 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1567 _FVMenuSaveAs(bv->fv);
1568 }
1569
1570 static void BVMenuGenerate(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1571 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1572 _FVMenuGenerate(bv->fv,false);
1573 }
1574
1575 static void BVMenuGenerateFamily(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1576 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1577 _FVMenuGenerate(bv->fv,gf_macfamily);
1578 }
1579
1580 static void BVMenuGenerateTTC(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1581 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1582 _FVMenuGenerate(bv->fv,gf_ttc);
1583 }
1584
1585 static void BVMenuExport(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1586 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1587 BVExport(bv);
1588 }
1589
1590 static void BVMenuImport(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1591 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1592 BVImport(bv);
1593 }
1594
1595 static void BVMenuRevert(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1596 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1597 FVDelay(bv->fv,(void (*)(FontView *)) FVRevert);
1598 /* The revert command can potentially */
1599 /* destroy our window (if the char weren't in the */
1600 /* old font). If that happens before the menu finishes */
1601 /* we get a crash. So delay till after the menu completes */
1602 }
1603
1604 static void fllistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1605 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1606
1607 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
1608 switch ( mi->mid ) {
1609 case BV_MID_Revert:
1610 mi->ti.disabled = bv->bdf->sf->origname==NULL || bv->bdf->sf->isnew;
1611 break;
1612 case BV_MID_Recent:
1613 mi->ti.disabled = !RecentFilesAny();
1614 break;
1615 }
1616 }
1617 }
1618
1619 static void BVMagnify(BitmapView *bv, int midx, int midy, int bigger) {
1620 /* available sizes: 1, 2, 3, 4, 6, 8, 12, 16, 24, 32 */
1621
1622 if ( bigger>0 ) {
1623 if ( bv->scale == 1 )
1624 bv->scale = 2;
1625 else if ( (bv->scale & (bv->scale - 1)) == 0 ) /* power of 2 */
1626 bv->scale += bv->scale / 2;
1627 else
1628 bv->scale += bv->scale / 3;
1629 if ( bv->scale > 32 ) bv->scale = 32;
1630 } else {
1631 if ( bv->scale <= 2 )
1632 bv->scale = 1;
1633 else if ( (bv->scale & (bv->scale - 1)) == 0 )
1634 bv->scale -= bv->scale / 4;
1635 else
1636 bv->scale -= bv->scale / 3;
1637 }
1638 bv->xoff = -(midx*bv->scale - bv->width/2);
1639 bv->yoff = -(midy*bv->scale - bv->height/2);
1640 BVNewScale(bv);
1641 }
1642
1643 static void BVMenuScale(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1644 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1645
1646 if ( mi->mid == BV_MID_Fit ) {
1647 BVFit(bv);
1648 } else {
1649 real midx = (bv->width/2-bv->xoff)/bv->scale;
1650 real midy = (bv->height/2-bv->yoff)/bv->scale;
1651 BVMagnify(bv,midx,midy,mi->mid==BV_MID_ZoomOut?-1:1);
1652 }
1653 }
1654
1655 static void BVMenuChangeChar(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1656 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1657 SplineFont *sf = bv->bc->sc->parent;
1658 EncMap *map = bv->fv->b.map;
1659 int pos = -1, gid;
1660
1661 if ( mi->mid == BV_MID_Next ) {
1662 pos = BVCurEnc(bv)+1;
1663 } else if ( mi->mid == BV_MID_Prev ) {
1664 pos = BVCurEnc(bv)-1;
1665 } else if ( mi->mid == BV_MID_NextDef ) {
1666 for ( pos = BVCurEnc(bv)+1; pos<map->enccount &&
1667 ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid]) ||
1668 bv->bdf->glyphs[gid]==NULL) ;
1669 ++pos );
1670 if ( pos==map->enccount )
1671 return;
1672 } else if ( mi->mid == BV_MID_PrevDef ) {
1673 for ( pos = BVCurEnc(bv)-1; pos>=0 &&
1674 ((gid=map->map[pos])==-1 || !SCWorthOutputting(sf->glyphs[gid]) ||
1675 bv->bdf->glyphs[gid]==NULL) ;
1676 --pos );
1677 if ( pos<0 )
1678 return;
1679 }
1680 if ( pos>=0 && pos<map->enccount )
1681 BVChangeChar(bv,pos,false);
1682 }
1683
1684 static void BVMenuChangePixelSize(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1685 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1686 BDFFont *best=NULL, *bdf;
1687 /* Bigger will find either a bigger pixelsize or a font with same pixelsize and greater depth */
1688
1689 if ( mi->mid == BV_MID_Bigger ) {
1690 best = bv->bdf->next; /* I rely on the bitmap list being ordered */
1691 } else {
1692 for ( bdf=bv->bdf->sf->bitmaps; bdf!=NULL && bdf->next!=bv->bdf; bdf=bdf->next );
1693 best = bdf;
1694 }
1695 if ( best!=NULL && bv->bdf!=best ) {
1696 bv->bdf = best;
1697 bv->scscale = ((real) (best->pixelsize))/(best->sf->ascent+best->sf->descent);
1698 BVChangeChar(bv,bv->enc,true);
1699 BVShows.lastpixelsize = best->pixelsize;
1700 }
1701 }
1702
1703 static void BVMenuGotoChar(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1704 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1705 int pos = GotoChar(bv->fv->b.sf,bv->fv->b.map,NULL);
1706
1707 if ( pos!=-1 )
1708 BVChangeChar(bv,pos,false);
1709 }
1710
1711 static void BVMenuFindInFontView(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1712 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1713
1714 FVChangeChar(bv->fv,bv->bc->sc->orig_pos);
1715 GDrawSetVisible(bv->fv->gw,true);
1716 GDrawRaise(bv->fv->gw);
1717 }
1718
1719 static void BVMenuPalettesDock(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1720 PalettesChangeDocking();
1721 }
1722
1723 static void BVMenuPaletteShow(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1724 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1725
1726 BVPaletteSetVisible(bv, mi->mid==BV_MID_Tools?1:mi->mid==BV_MID_Shades?2:0, !BVPaletteIsVisible(bv, mi->mid==BV_MID_Tools?1:mi->mid==BV_MID_Shades?2:0));
1727 }
1728
1729 static void BVUndo(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1730 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1731 if ( bv->bc->undoes==NULL )
1732 return;
1733 BCDoUndo(bv->bc);
1734 }
1735
1736 static SplineChar *SCofBV(BitmapView *bv) {
1737 SplineFont *sf = bv->bdf->sf;
1738 int i, cid = bv->bc->orig_pos;
1739
1740 if ( sf->subfonts ) {
1741 for ( i=0; i<sf->subfontcnt; ++i )
1742 if ( cid<sf->subfonts[i]->glyphcnt && sf->subfonts[i]->glyphs[cid]!=NULL )
1743 return( sf->subfonts[i]->glyphs[cid] );
1744
1745 return( NULL );
1746 } else
1747 return( sf->glyphs[cid] );
1748 }
1749
1750 static void BVMenuSetWidth(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1751 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1752 char buffer[10];
1753 char *ret;
1754 BDFFont *bdf;
1755 int mysize = bv->bdf->pixelsize;
1756 SplineChar *sc;
1757 int val;
1758
1759 if ( !bv->bdf->sf->onlybitmaps )
1760 return;
1761 if ( mi->mid==BV_MID_SetWidth ) {
1762 sprintf( buffer,"%d",bv->bc->width);
1763 ret = gwwv_ask_string(_("Set Width..."),buffer,_("Set Width..."));
1764 } else {
1765 sprintf( buffer,"%d",bv->bc->vwidth);
1766 ret = gwwv_ask_string(_("Set Vertical Width..."),buffer,_("Set Vertical Width..."));
1767 }
1768 if ( ret==NULL )
1769 return;
1770 val = strtol(ret,NULL,10);
1771 free(ret);
1772 if ( val<0 )
1773 return;
1774 if ( mi->mid==BV_MID_SetWidth )
1775 bv->bc->width = val;
1776 else
1777 bv->bc->vwidth = val;
1778 BCCharChangedUpdate(bv->bc);
1779 for ( bdf=bv->bdf->sf->bitmaps; bdf!=NULL; bdf=bdf->next )
1780 if ( bdf->pixelsize > mysize )
1781 return;
1782 if ( (sc=SCofBV(bv))!=NULL ) {
1783 if ( mi->mid==BV_MID_SetWidth )
1784 sc->width = val*(sc->parent->ascent+sc->parent->descent)/mysize;
1785 else
1786 sc->vwidth = val*(sc->parent->ascent+sc->parent->descent)/mysize;
1787 SCCharChangedUpdate(sc,ly_none);
1788 }
1789 }
1790
1791 static void BVRedo(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1792 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1793 if ( bv->bc->redoes==NULL )
1794 return;
1795 BCDoRedo(bv->bc);
1796 }
1797
1798 static void _BVUnlinkRef(BitmapView *bv) {
1799 int anyrefs = false;
1800 BDFRefChar *ref, *next;
1801
1802 if ( bv->bc->refs!=NULL ) {
1803 BCPreserveState(bv->bc);
1804 for ( ref=bv->bc->refs; ref!=NULL && !anyrefs; ref=ref->next )
1805 if ( ref->selected ) anyrefs = true;
1806 for ( ref=bv->bc->refs; ref!=NULL ; ref=next ) {
1807 next = ref->next;
1808 if ( ref->selected || !anyrefs) {
1809 BCPasteInto( bv->bc,ref->bdfc,ref->xoff,ref->yoff,false,false );
1810 BCMergeReferences( bv->bc,ref->bdfc,ref->xoff,ref->yoff );
1811 BCRemoveDependent( bv->bc,ref );
1812 }
1813 }
1814 BCCharChangedUpdate(bv->bc);
1815 }
1816 }
1817
1818 static void BVUnlinkRef(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1819 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1820 _BVUnlinkRef(bv);
1821 }
1822
1823 static void BVRemoveUndoes(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1824 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1825 UndoesFree(bv->bc->undoes); bv->bc->undoes = NULL;
1826 UndoesFree(bv->bc->redoes); bv->bc->redoes = NULL;
1827 }
1828
1829 static void BVCopy(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1830 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1831 BCCopySelected(bv->bc,bv->bdf->pixelsize,BDFDepth(bv->bdf));
1832 }
1833
1834 static void BVCopyRef(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1835 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1836 BCCopyReference(bv->bc,bv->bdf->pixelsize,BDFDepth(bv->bdf));
1837 }
1838
1839 static void BVDoClear(BitmapView *bv) {
1840 BDFRefChar *head, *next;
1841 BDFChar *bc = bv->bc;
1842 int refs_changed = false;
1843
1844 for ( head=bc->refs; head!=NULL; head=next ) {
1845 next = head->next;
1846 if ( head->selected ) {
1847 if ( !refs_changed ) {
1848 BCPreserveState( bc );
1849 refs_changed = true;
1850 }
1851 BCRemoveDependent( bc,head );
1852 }
1853 }
1854
1855 if ( bc->selection!=NULL ) {
1856 BCPreserveState( bc );
1857 BDFFloatFree( bc->selection );
1858 bv->bc->selection = NULL;
1859 BCCharChangedUpdate( bc );
1860 } else if ( refs_changed ) {
1861 BCCharChangedUpdate( bc );
1862 }
1863 }
1864
1865 static void BVClear(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1866 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1867 BVDoClear(bv);
1868 }
1869
1870 static void BVPaste(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1871 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1872 if ( CopyContainsBitmap())
1873 PasteToBC(bv->bc,bv->bdf->pixelsize,BDFDepth(bv->bdf));
1874 }
1875
1876 static void BVCut(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1877 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1878 BVCopy(gw,mi,e);
1879 BVDoClear(bv);
1880 }
1881
1882 static void BVSelectAll(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1883 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1884 BDFChar *bc = bv->bc;
1885
1886 BDFFloatCreate(bc,bc->xmin,bc->xmax,bc->ymin,bc->ymax, true);
1887 BCCharUpdate(bc);
1888 }
1889
1890 static void BVMenuFontInfo(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1891 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1892 DelayEvent(FontMenuFontInfo,bv->fv);
1893 }
1894
1895 static void BVMenuBDFInfo(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1896 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1897 SFBdfProperties(bv->bdf->sf,bv->fv->b.map,bv->bdf);
1898 }
1899
1900 static void BVMenuGetInfo(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1901 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1902 SCCharInfo(bv->bc->sc,bv->fv->b.active_layer,bv->fv->b.map,BVCurEnc(bv));
1903 }
1904
1905 static void BVMenuBitmaps(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1906 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1907 BitmapDlg(&bv->fv->b,gw,bv->bc->sc,mi->mid==BV_MID_AvailBitmaps );
1908 }
1909
1910 static void BVMenuRmGlyph(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1911 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1912 BitmapView *bvs, *bvnext;
1913 BDFFont *bdf = bv->bdf;
1914 BDFChar *bc = bv->bc;
1915 FontView *fv;
1916
1917 for ( bvs=bc->views; bvs!=NULL; bvs=bvnext ) {
1918 bvnext = bvs->next;
1919 GDrawDestroyWindow(bvs->gw);
1920 }
1921 bdf->glyphs[bc->orig_pos] = NULL;
1922 /* Can't free the glyph yet, need to process all the destroy events */
1923 /* which touch bc->views first */
1924 DelayEvent( (void (*)(void *))BDFCharFree,bc);
1925 for ( fv = (FontView *) (bdf->sf->fv); fv!=NULL; fv=(FontView *) (fv->b.nextsame) )
1926 GDrawRequestExpose(fv->v,NULL,false);
1927 }
1928
1929 static int askfraction(int *xoff, int *yoff) {
1930 static int lastx=1, lasty = 3;
1931 char buffer[30];
1932 char *ret, *end, *end2;
1933 int xv, yv;
1934
1935 sprintf( buffer, "%d:%d", lastx, lasty );
1936 ret = ff_ask_string(_("Skew"),buffer,_("Skew Ratio"));
1937 if ( ret==NULL )
1938 return( 0 );
1939 xv = strtol(ret,&end,10);
1940 yv = strtol(end+1,&end2,10);
1941 if ( xv==0 || xv>10 || xv<-10 || yv<=0 || yv>10 || *end!=':' || *end2!='\0' ) {
1942 ff_post_error( _("Bad Number"),_("Bad Number") );
1943 free(ret);
1944 return( 0 );
1945 }
1946 free(ret);
1947 *xoff = lastx = xv; *yoff = lasty = yv;
1948 return( 1 );
1949 }
1950
1951 void BVRotateBitmap(BitmapView *bv,enum bvtools type ) {
1952 int xoff=0, yoff=0;
1953
1954 if ( type==bvt_skew )
1955 if ( !askfraction(&xoff,&yoff))
1956 return;
1957 BCPreserveState(bv->bc);
1958 BCTransFunc(bv->bc,type,xoff,yoff);
1959 BCCharChangedUpdate(bv->bc);
1960 }
1961
1962 void BVMenuRotateInvoked(GWindow gw,struct gmenuitem *mi,GEvent *g) {
1963 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1964 BVRotateBitmap(bv,mi->mid);
1965 }
1966
1967 static void ellistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1968 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1969
1970 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
1971 switch ( mi->mid ) {
1972 case BV_MID_RegenBitmaps:
1973 mi->ti.disabled = bv->bdf->sf->onlybitmaps;
1974 break;
1975 }
1976 }
1977 }
1978
1979 static void edlistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
1980 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
1981 BDFRefChar *cur;
1982
1983 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
1984 switch ( mi->mid ) {
1985 case BV_MID_Cut: /*case BV_MID_Copy:*/ case BV_MID_Clear:
1986 /* If nothing is selected, copy copies everything */
1987 mi->ti.disabled = bv->bc->selection==NULL;
1988 for ( cur=bv->bc->refs; cur!=NULL && mi->ti.disabled; cur=cur->next ) {
1989 if ( cur->selected )
1990 mi->ti.disabled = false;
1991 }
1992 break;
1993 case BV_MID_Paste:
1994 mi->ti.disabled = !CopyContainsBitmap();
1995 break;
1996 case BV_MID_Undo:
1997 mi->ti.disabled = bv->bc->undoes==NULL;
1998 break;
1999 case BV_MID_Redo:
2000 mi->ti.disabled = bv->bc->redoes==NULL;
2001 break;
2002 case BV_MID_RemoveUndoes:
2003 mi->ti.disabled = bv->bc->redoes==NULL && bv->bc->undoes==NULL;
2004 break;
2005 case BV_MID_UnlinkRef:
2006 mi->ti.disabled = bv->bc->refs==NULL;
2007 break;
2008 }
2009 }
2010 }
2011
2012 static void pllistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
2013 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
2014 extern int palettes_docked;
2015
2016 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
2017 switch ( mi->mid ) {
2018 case BV_MID_Tools:
2019 mi->ti.checked = BVPaletteIsVisible(bv,1);
2020 break;
2021 case BV_MID_Layers:
2022 mi->ti.checked = BVPaletteIsVisible(bv,0);
2023 break;
2024 case BV_MID_Shades:
2025 mi->ti.disabled = BDFDepth(bv->bdf)==1;
2026 if ( !mi->ti.disabled )
2027 mi->ti.checked = BVPaletteIsVisible(bv,2);
2028 break;
2029 case BV_MID_DockPalettes:
2030 mi->ti.checked = palettes_docked;
2031 break;
2032 }
2033 }
2034 }
2035
2036 static void vwlistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
2037 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
2038 BDFFont *bdf;
2039
2040 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
2041 switch ( mi->mid ) {
2042 case BV_MID_ZoomIn:
2043 mi->ti.disabled = bv->scale==32;
2044 break;
2045 case BV_MID_ZoomOut:
2046 mi->ti.checked = bv->scale==1;
2047 break;
2048 case BV_MID_Bigger:
2049 mi->ti.disabled = bv->bdf->next==NULL;
2050 break;
2051 case BV_MID_Smaller:
2052 for ( bdf=bv->bdf->sf->bitmaps; bdf!=NULL && bdf->next!=bv->bdf; bdf=bdf->next );
2053 mi->ti.disabled = bdf==NULL;
2054 break;
2055 }
2056 }
2057 }
2058
2059 static void mtlistcheck(GWindow gw,struct gmenuitem *mi,GEvent *e) {
2060 BitmapView *bv = (BitmapView *) GDrawGetUserData(gw);
2061
2062 for ( mi = mi->sub; mi->ti.text!=NULL || mi->ti.line ; ++mi ) {
2063 switch ( mi->mid ) {
2064 case BV_MID_SetWidth:
2065 mi->ti.disabled = !bv->bdf->sf->onlybitmaps;
2066 break;
2067 case BV_MID_SetVWidth:
2068 mi->ti.disabled = !bv->bdf->sf->onlybitmaps || !bv->bdf->sf->hasvmetrics;
2069 break;
2070 }
2071 }
2072 }
2073
2074 static struct resed bitmapview_re[] = {
2075 { N_("FG Color"), "BitmapColor", rt_color, &bitmap_color, N_("The color of the large bitmap"), NULL, { 0 }, 0, 0 },
2076 { N_("Overview FG Color"), "OverviewColor", rt_color, &overview_fg_color, N_("The color of the small bitmap view"), NULL, { 0 }, 0, 0 },
2077 { N_("Guide Color"), "GuideColor", rt_color, &guide_color, N_("The color of the guide lines for glyph metrics"), NULL, { 0 }, 0, 0 },
2078 { N_("Width Guide Color"), "WidthGuideColor", rt_color, &width_guide_color, N_("The color of the guide line for the advance width"), NULL, { 0 }, 0, 0 },
2079 { N_("Grid Color"), "GridColor", rt_color, &grid_color, N_("The color of the guide lines for the bitmap grid"), NULL, { 0 }, 0, 0 },
2080 { N_("Outline Color"), "OutlineColor", rt_color, &outline_color, N_("The color of the outline"), NULL, { 0 }, 0, 0 },
2081 { N_("Active Tool Color"), "ActiveToolColor", rt_color, &active_tool_color, N_("The color of the preview for drawing lines, rectangles, and ellipses"), NULL, { 0 }, 0, 0 },
2082 { N_("Selected Region Color"), "SelectedRegionColor", rt_color, &selection_color, N_("The color of the selected region"), NULL, { 0 }, 0, 0 },
2083 { N_("Reference FG Color"), "ReferenceColor", rt_color, &ref_color, N_("The color of a reference"), NULL, { 0 }, 0, 0 },
2084 { N_("Selected Reference Color"), "SelectedReferenceColor", rt_color, &selected_ref_color, N_("The color of the selected reference"), NULL, { 0 }, 0, 0 },
2085 { N_("Reference Border Color"), "ReferenceBorderColor", rt_color, &ref_border_color, N_("The color used to outline a reference"), NULL, { 0 }, 0, 0 },
2086 { N_("Selected Reference Border Color"), "SelectedReferenceBorderColor", rt_color, &selected_ref_border_color, N_("The color used to outline the selected reference"), NULL, { 0 }, 0, 0 },
2087 RESED_EMPTY
2088 };
2089
2090 extern GResInfo metricsview_ri;
2091 GResInfo bitmapview_ri = {
2092 &metricsview_ri, NULL,NULL, NULL,
2093 NULL,
2094 NULL,
2095 NULL,
2096 bitmapview_re,
2097 N_("Bitmap View"),
2098 N_("This window displays a single bitmap glyph"),
2099 "BitmapView",
2100 "fontforge",
2101 false,
2102 false,
2103 0,
2104 GBOX_EMPTY,
2105 GBOX_EMPTY,
2106 NULL,
2107 NULL,
2108 NULL
2109 };
2110
2111 void BVColInit(void) {
2112 extern GResInfo charviewpoints_ri;
2113 GResEditDoInit(&bitmapview_ri);
2114 GResEditDoInit(&charviewpoints_ri);
2115 }
2116
2117 static GMenuItem2 wnmenu[] = {
2118 { { (unichar_t *) N_("New O_utline Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("New Outline Window|Ctl+H"), NULL, NULL, BVMenuOpenOutline, 0 },
2119 { { (unichar_t *) N_("New _Bitmap Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 1, 0, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("New Bitmap Window|Ctl+J"), NULL, NULL, /* No function, never avail */NULL, 0 },
2120 { { (unichar_t *) N_("New _Metrics Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("New Metrics Window|Ctl+K"), NULL, NULL, BVMenuOpenMetrics, 0 },
2121 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2122 { { (unichar_t *) N_("Warnings"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, H_("Warnings|No Shortcut"), NULL, NULL, _MenuWarnings, BV_MID_Warnings },
2123 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2124 GMENUITEM2_EMPTY
2125 };
2126
2127 static void BVWindowMenuBuild(GWindow gw,struct gmenuitem *mi,GEvent *e) {
2128 struct gmenuitem *wmi;
2129 WindowMenuBuild(gw,mi,e);
2130 for ( wmi = mi->sub; wmi->ti.text!=NULL || wmi->ti.line ; ++wmi ) {
2131 switch ( wmi->mid ) {
2132 case BV_MID_Warnings:
2133 wmi->ti.disabled = ErrorWindowExists();
2134 break;
2135 }
2136 }
2137 }
2138
2139 static void BVMenuContextualHelp(GWindow base,struct gmenuitem *mi,GEvent *e) {
2140 help("ui/mainviews/bitmapview.html", NULL);
2141 }
2142
2143 char *BVFlipNames[] = { N_("Flip Horizontally"), N_("Flip Vertically"),
2144 /* GT: "CW" means Clockwise */
2145 NU_("Rotate 90° CW"),
2146 /* GT: "CW" means Counter-Clockwise */
2147 NU_("Rotate 90° CCW"),
2148 NU_("Rotate 180°"),
2149 N_("Skew..."), NULL };
2150
2151 static GMenuItem2 dummyitem[] = {
2152 { { (unichar_t *) N_("Font|_New"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, NULL, NULL, NULL, NULL, 0 },
2153 GMENUITEM2_EMPTY
2154 };
2155 static GMenuItem2 fllist[] = {
2156 { { (unichar_t *) N_("Font|_New"), (GImage *) "filenew.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, H_("New|Ctl+N"), NULL, NULL, MenuNew, 0 },
2157 { { (unichar_t *) N_("_Open"), (GImage *) "fileopen.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'O' }, H_("Open|Ctl+O"), NULL, NULL, BVMenuOpen, 0 },
2158 { { (unichar_t *) N_("Recen_t"), (GImage *) "filerecent.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, NULL, dummyitem, MenuRecentBuild, NULL, BV_MID_Recent },
2159 { { (unichar_t *) N_("_Close"), (GImage *) "fileclose.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Close|Ctl+Shft+Q"), NULL, NULL, BVMenuClose, 0 },
2160 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2161 { { (unichar_t *) N_("_Save"), (GImage *) "filesave.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Save|Ctl+S"), NULL, NULL, BVMenuSave, 0 },
2162 { { (unichar_t *) N_("S_ave as..."), (GImage *) "filesaveas.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'a' }, H_("Save as...|Ctl+Shft+S"), NULL, NULL, BVMenuSaveAs, 0 },
2163 { { (unichar_t *) N_("_Generate Fonts..."), (GImage *) "filegenerate.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'G' }, H_("Generate Fonts...|Ctl+Shft+G"), NULL, NULL, BVMenuGenerate, 0 },
2164 { { (unichar_t *) N_("Generate Mac _Family..."), (GImage *) "filegeneratefamily.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Generate Mac Family...|Alt+Ctl+G"), NULL, NULL, BVMenuGenerateFamily, 0 },
2165 { { (unichar_t *) N_("Generate TTC..."), (GImage *) "filegeneratefamily.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Generate TTC...|No Shortcut"), NULL, NULL, BVMenuGenerateTTC, 0 },
2166 { { (unichar_t *) N_("Expor_t..."), (GImage *) "fileexport.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, H_("Export...|No Shortcut"), NULL, NULL, BVMenuExport, 0 },
2167 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2168 { { (unichar_t *) N_("_Import..."), (GImage *) "fileimport.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Import...|Ctl+Shft+I"), NULL, NULL, BVMenuImport, 0 },
2169 { { (unichar_t *) N_("_Revert File"), (GImage *) "filerevert.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Revert File|Ctl+Shft+R"), NULL, NULL, BVMenuRevert, BV_MID_Revert },
2170 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2171 { { (unichar_t *) N_("Pr_eferences..."), (GImage *) "fileprefs.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Preferences...|No Shortcut"), NULL, NULL, MenuPrefs, 0 },
2172 { { (unichar_t *) N_("Appea_rance Editor..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Appearance Editor...|No Shortcut"), NULL, NULL, MenuXRes, 0 },
2173 #ifndef _NO_PYTHON
2174 { { (unichar_t *) N_("Config_ure Plugins..."), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'u' }, H_("Configure Plugins...|No Shortcut"), NULL, NULL, MenuPlug, 0 },
2175 #endif
2176 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2177 { { (unichar_t *) N_("_Quit"), (GImage *) "filequit.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'Q' }, H_("Quit|Ctl+Q"), NULL, NULL, MenuExit, 0 },
2178 GMENUITEM2_EMPTY
2179 };
2180
2181 static GMenuItem2 edlist[] = {
2182 { { (unichar_t *) N_("_Undo"), (GImage *) "editundo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'U' }, H_("Undo|Ctl+Z"), NULL, NULL, BVUndo, BV_MID_Undo },
2183 { { (unichar_t *) N_("_Redo"), (GImage *) "editredo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Redo|Ctl+Y"), NULL, NULL, BVRedo, BV_MID_Redo },
2184 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2185 { { (unichar_t *) N_("Cu_t"), (GImage *) "editcut.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 't' }, H_("Cut|Ctl+X"), NULL, NULL, BVCut, BV_MID_Cut },
2186 { { (unichar_t *) N_("_Copy"), (GImage *) "editcopy.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'C' }, H_("Copy|Ctl+C"), NULL, NULL, BVCopy, BV_MID_Copy },
2187 { { (unichar_t *) N_("C_opy Reference"), (GImage *) "editcopyref.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Copy Reference|Ctl+G"), NULL, NULL, BVCopyRef, BV_MID_CopyRef },
2188 { { (unichar_t *) N_("_Paste"), (GImage *) "editpaste.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Paste|Ctl+V"), NULL, NULL, BVPaste, BV_MID_Paste },
2189 { { (unichar_t *) N_("C_lear"), (GImage *) "editclear.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, H_("Clear|Delete"), NULL, NULL, BVClear, BV_MID_Clear },
2190 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2191 { { (unichar_t *) N_("Select _All"), (GImage *) "editselect.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Select All|Ctl+A"), NULL, NULL, BVSelectAll, BV_MID_SelAll },
2192 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2193 { { (unichar_t *) N_("Remo_ve Undoes"), (GImage *) "menuempty.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'e' }, H_("Remove Undoes|No Shortcut"), NULL, NULL, BVRemoveUndoes, BV_MID_RemoveUndoes },
2194 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2195 { { (unichar_t *) N_("U_nlink Reference"), (GImage *) "editunlink.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'U' }, H_("Unlink Reference|Ctl+U"), NULL, NULL, BVUnlinkRef, BV_MID_UnlinkRef },
2196 GMENUITEM2_EMPTY
2197 };
2198
2199 static GMenuItem2 trlist[] = {
2200 { { (unichar_t *) N_("Flip _Horizontally"), (GImage *) "transformfliphor.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, H_("Flip Horizontally|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_fliph },
2201 { { (unichar_t *) N_("Flip _Vertically"), (GImage *) "transformflipvert.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Flip Vertically|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_flipv },
2202 { { (unichar_t *) NU_("_Rotate 90° CW"), (GImage *) "transformrotatecw.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'R' }, H_("Rotate 90 CW|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_rotate90cw },
2203 { { (unichar_t *) NU_("Rotate _90° CCW"), (GImage *) "transformrotateccw.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '9' }, H_("Rotate 90 CCW|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_rotate90ccw },
2204 { { (unichar_t *) NU_("Rotate _180°"), (GImage *) "transformrotate180.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, '1' }, H_("Rotate 180|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_rotate180 },
2205 { { (unichar_t *) N_("_Skew..."), (GImage *) "transformskew.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Skew...|No Shortcut"), NULL, NULL, BVMenuRotateInvoked, bvt_skew },
2206 GMENUITEM2_EMPTY
2207 };
2208
2209 static GMenuItem2 ellist[] = {
2210 { { (unichar_t *) N_("_Font Info..."), (GImage *) "elementfontinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Font Info...|Ctl+Shft+F"), NULL, NULL, BVMenuFontInfo, 0 },
2211 { { (unichar_t *) N_("Glyph _Info..."), (GImage *) "elementglyphinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("Glyph Info...|Ctl+I"), NULL, NULL, BVMenuGetInfo, BV_MID_GetInfo },
2212 { { (unichar_t *) N_("BDF Info..."), (GImage *) "elementbdfinfo.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'I' }, H_("BDF Info...|No Shortcut"), NULL, NULL, BVMenuBDFInfo, 0 },
2213 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2214 { { (unichar_t *) N_("Bitm_ap Strikes Available..."), (GImage *) "elementbitmapsavail.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'A' }, H_("Bitmap Strikes Available...|Ctl+Shft+B"), NULL, NULL, BVMenuBitmaps, BV_MID_AvailBitmaps },
2215 { { (unichar_t *) N_("Regenerate _Bitmap Glyphs..."), (GImage *) "elementregenbitmaps.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Regenerate Bitmap Glyphs...|Ctl+B"), NULL, NULL, BVMenuBitmaps, BV_MID_RegenBitmaps },
2216 { { (unichar_t *) N_("Remove This Glyph"), (GImage *) "elementremovebitmaps.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Remove This Glyph|No Shortcut"), NULL, NULL, BVMenuRmGlyph, 0 },
2217 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2218 { { (unichar_t *) N_("_Transformations"), (GImage *) "elementtransform.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'T' }, NULL, trlist, NULL, NULL, 0 },
2219 GMENUITEM2_EMPTY
2220 };
2221
2222 static GMenuItem2 pllist[] = {
2223 { { (unichar_t *) N_("_Tools"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'T' }, H_("Tools|No Shortcut"), NULL, NULL, BVMenuPaletteShow, BV_MID_Tools },
2224 { { (unichar_t *) N_("_Layers"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'L' }, H_("Layers|No Shortcut"), NULL, NULL, BVMenuPaletteShow, BV_MID_Layers },
2225 { { (unichar_t *) N_("_Shades"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'S' }, H_("Shades|No Shortcut"), NULL, NULL, BVMenuPaletteShow, BV_MID_Shades },
2226 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2227 { { (unichar_t *) N_("_Docked Palettes"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 1, 0, 0, 0, 1, 1, 0, 'D' }, H_("Docked Palettes|No Shortcut"), NULL, NULL, BVMenuPalettesDock, BV_MID_DockPalettes },
2228 GMENUITEM2_EMPTY
2229 };
2230
2231 static GMenuItem2 vwlist[] = {
2232 { { (unichar_t *) N_("_Fit"), (GImage *) "viewfit.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, H_("Fit|Ctl+F"), NULL, NULL, BVMenuScale, BV_MID_Fit },
2233 { { (unichar_t *) N_("Z_oom out"), (GImage *) "viewzoomout.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'o' }, H_("Zoom out|Alt+Ctl+-"), NULL, NULL, BVMenuScale, BV_MID_ZoomOut },
2234 { { (unichar_t *) N_("Zoom _in"), (GImage *) "viewzoomin.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'i' }, H_("Zoom in|Alt+Ctl+Shft++"), NULL, NULL, BVMenuScale, BV_MID_ZoomIn },
2235 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2236 { { (unichar_t *) N_("_Next Glyph"), (GImage *) "viewnext.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'N' }, H_("Next Glyph|Ctl+]"), NULL, NULL, BVMenuChangeChar, BV_MID_Next },
2237 { { (unichar_t *) N_("_Prev Glyph"), (GImage *) "viewprev.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'P' }, H_("Prev Glyph|Ctl+["), NULL, NULL, BVMenuChangeChar, BV_MID_Prev },
2238 { { (unichar_t *) N_("Next _Defined Glyph"), (GImage *) "viewnextdef.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'D' }, H_("Next Defined Glyph|Alt+Ctl+]"), NULL, NULL, BVMenuChangeChar, BV_MID_NextDef },
2239 { { (unichar_t *) N_("Prev Defined Gl_yph"), (GImage *) "viewprevdef.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'a' }, H_("Prev Defined Glyph|Alt+Ctl+["), NULL, NULL, BVMenuChangeChar, BV_MID_PrevDef },
2240 { { (unichar_t *) N_("_Goto"), (GImage *) "viewgoto.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'G' }, H_("Goto|Ctl+Shft+>"), NULL, NULL, BVMenuGotoChar, 0 },
2241 { { (unichar_t *) N_("Find In Font _View"), (GImage *) "viewfindinfont.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, H_("Find In Font View|Ctl+Shft+<"), NULL, NULL, BVMenuFindInFontView, 0 },
2242 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2243 { { (unichar_t *) N_("_Bigger Pixel Size"), (GImage *) "viewbiggersize.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'B' }, H_("Bigger Pixel Size|Ctl+Shft++"), NULL, NULL, BVMenuChangePixelSize, BV_MID_Bigger },
2244 { { (unichar_t *) N_("_Smaller Pixel Size"), (GImage *) "viewsmallersize.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'S' }, H_("Smaller Pixel Size|Ctl+-"), NULL, NULL, BVMenuChangePixelSize, BV_MID_Smaller },
2245 { { NULL, NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 1, 0, 0, 0, '\0' }, NULL, NULL, NULL, NULL, 0 }, /* line */
2246 { { (unichar_t *) N_("_Palettes"), (GImage *) "viewpalettes.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, NULL, pllist, pllistcheck, NULL, 0 },
2247 GMENUITEM2_EMPTY
2248 };
2249
2250 static GMenuItem2 mtlist[] = {
2251 { { (unichar_t *) N_("Set _Width..."), (GImage *) "metricssetwidth.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Set Width...|Ctl+Shft+L"), NULL, NULL, BVMenuSetWidth, BV_MID_SetWidth },
2252 { { (unichar_t *) N_("Set _Vertical Width..."), (GImage *) "metricssetvwidth.png", COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, H_("Set Vertical Width...|Ctl+Shft+L"), NULL, NULL, BVMenuSetWidth, BV_MID_SetVWidth },
2253 GMENUITEM2_EMPTY
2254 };
2255
2256 static GMenuItem2 mblist[] = {
2257 { { (unichar_t *) N_("_File"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'F' }, NULL, fllist, fllistcheck, NULL, 0 },
2258 { { (unichar_t *) N_("_Edit"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'E' }, NULL, edlist, edlistcheck, NULL, 0 },
2259 { { (unichar_t *) N_("E_lement"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'l' }, NULL, ellist, ellistcheck, NULL, 0 },
2260 { { (unichar_t *) N_("_View"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'V' }, NULL, vwlist, vwlistcheck, NULL, 0 },
2261 { { (unichar_t *) N_("_Metrics"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'M' }, NULL, mtlist, mtlistcheck, NULL, 0 },
2262 { { (unichar_t *) N_("_Window"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'W' }, NULL, wnmenu, BVWindowMenuBuild, NULL, 0 },
2263 { { (unichar_t *) N_("_Help"), NULL, COLOR_DEFAULT, COLOR_DEFAULT, NULL, NULL, 0, 1, 0, 0, 0, 0, 1, 1, 0, 'H' }, NULL, helplist, NULL, NULL, 0 },
2264 GMENUITEM2_EMPTY
2265 };
2266
2267 #define bitmap_width 16
2268 #define bitmap_height 16
2269 static unsigned char bitmap_bits[] = {
2270 0x00, 0x00, 0xfc, 0x03, 0xfc, 0x03, 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c,
2271 0x30, 0x0c, 0xf0, 0x03, 0xf0, 0x03, 0x30, 0x0c, 0x30, 0x0c, 0x30, 0x0c,
2272 0x30, 0x0c, 0xfc, 0x03, 0xfc, 0x03, 0x00, 0x00};
2273
2274 static int bitmapview_ready = false;
2275
2276 static void BitmapViewFinish() {
2277 if ( !bitmapview_ready ) return;
2278 bitmapview_ready = 0;
2279 mb2FreeGetText(mblist);
2280 }
2281
2282 void BitmapViewFinishNonStatic() {
2283 BitmapViewFinish();
2284 }
2285
2286 static void BitmapViewInit(void) {
2287 // static int done = false; // superseded by bitmapview_ready.
2288 int i;
2289
2290 if ( bitmapview_ready )
2291 return;
2292 bitmapview_ready = true;
2293
2294 mb2DoGetText(mblist);
2295 for ( i=0; BVFlipNames[i]!=NULL ; ++i )
2296 BVFlipNames[i] = S_(BVFlipNames[i]);
2297 BVColInit();
2298 atexit(&BitmapViewFinishNonStatic);
2299 }
2300
2301 BitmapView *BitmapViewCreate(BDFChar *bc, BDFFont *bdf, FontView *fv, int enc) {
2302 BitmapView *bv = calloc(1,sizeof(BitmapView));
2303 GRect pos, zoom, size;
2304 GWindow gw;
2305 GWindowAttrs wattrs;
2306 GGadgetData gd;
2307 GRect gsize;
2308 int sbsize;
2309 char buf[300];
2310 static GWindow icon = NULL;
2311 GTextInfo ti;
2312 int as, ds, ld;
2313
2314 BitmapViewInit();
2315
2316 BVShows.lastpixelsize = bdf->pixelsize;
2317
2318 if ( icon==NULL )
2319 icon = GDrawCreateBitmap(NULL,bitmap_width,bitmap_height,bitmap_bits);
2320
2321 bv->bc = bc;
2322 bv->scale = 1;
2323 bv->xoff = bv->yoff = 20;
2324 bv->next = bc->views;
2325 bc->views = bv;
2326 bv->fv = fv;
2327 bv->enc = enc;
2328 bv->map_of_enc = fv->b.map;
2329 bv->bdf = bdf;
2330 bv->color = 255;
2331 bv->shades_hidden = bdf->clut==NULL;
2332
2333 bv->showfore = BVShows.showfore;
2334 bv->showoutline = BVShows.showoutline;
2335 bv->showgrid = BVShows.showgrid;
2336 bv->scscale = ((real) (bdf->pixelsize))/(bdf->sf->ascent+bdf->sf->descent);
2337
2338 memset(&wattrs,0,sizeof(wattrs));
2339 wattrs.mask = wam_events|wam_cursor|wam_utf8_wtitle|wam_utf8_ititle;
2340 wattrs.event_masks = ~(1<<et_charup);
2341 wattrs.cursor = ct_pointer;
2342 wattrs.utf8_icon_title = BVMakeTitles(bv,bc,buf);
2343 wattrs.utf8_window_title = buf;
2344 wattrs.icon = icon;
2345 if ( wattrs.icon )
2346 wattrs.mask |= wam_icon;
2347 pos.x = 8+9*16+10; pos.width=bv_width; pos.height = bv_height;
2348 DefaultY(&pos);
2349
2350 bv->gw = gw = GDrawCreateTopWindow(NULL,&pos,bv_e_h,bv,&wattrs);
2351 free( (unichar_t *) wattrs.icon_title );
2352 GDrawSetWindowTypeName(bv->gw, "BitmapView");
2353
2354 GDrawGetSize(GDrawGetRoot(screen_display),&zoom);
2355 zoom.x = BVPalettesWidth(); zoom.width -= zoom.x-10;
2356 zoom.height -= 30; /* Room for title bar & such */
2357 GDrawSetZoom(gw,&zoom,-1);
2358
2359 memset(&gd,0,sizeof(gd));
2360 gd.flags = gg_visible | gg_enabled;
2361 helplist[0].invoke = BVMenuContextualHelp;
2362 gd.u.menu2 = mblist;
2363 bv->mb = GMenu2BarCreate( gw, &gd, NULL);
2364 GGadgetGetSize(bv->mb,&gsize);
2365 bv->mbh = gsize.height;
2366 bv->infoh = GDrawPointsToPixels(gw,36);
2367
2368 gd.pos.y = bv->mbh+bv->infoh;
2369 gd.pos.width = sbsize = GDrawPointsToPixels(gw,_GScrollBar_Width);
2370 gd.pos.height = pos.height-bv->mbh-bv->infoh - sbsize;
2371 gd.pos.x = pos.width-sbsize;
2372 gd.u.sbinit = NULL;
2373 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels|gg_sb_vert;
2374 bv->vsb = GScrollBarCreate(gw,&gd,bv);
2375
2376 gd.pos.y = pos.height-sbsize; gd.pos.height = sbsize;
2377 gd.pos.width = pos.width - sbsize;
2378 gd.pos.x = 0;
2379 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels;
2380 bv->hsb = GScrollBarCreate(gw,&gd,bv);
2381
2382 memset(&gd, '\0', sizeof(gd));
2383 memset(&ti, '\0', sizeof(ti));
2384 gd.pos.x = pos.width - GDrawPointsToPixels(gw,111);
2385 gd.pos.y = bv->mbh + GDrawPointsToPixels(gw,6);
2386 /*gd.pos.width = GDrawPointsToPixels(gw,106);*/
2387 gd.label = &ti;
2388 ti.text = (unichar_t *) _("Recalculate Bitmaps");
2389 ti.text_is_1byte = true;
2390 gd.flags = gg_visible|gg_enabled|gg_pos_in_pixels;
2391 if ( fv->b.sf->onlybitmaps )
2392 gd.flags = gg_pos_in_pixels;
2393 gd.handle_controlevent = BVRecalc;
2394 bv->recalc = GButtonCreate(gw,&gd,bv);
2395 GGadgetGetSize(bv->recalc,&size);
2396 GGadgetMove(bv->recalc,pos.width - size.width - GDrawPointsToPixels(gw,6),size.y);
2397
2398 pos.y = bv->mbh+bv->infoh; pos.height -= bv->mbh + sbsize + bv->infoh;
2399 pos.x = 0; pos.width -= sbsize;
2400 wattrs.mask = wam_events|wam_cursor|wam_backcol;
2401 wattrs.background_color = view_bgcol;
2402 wattrs.event_masks = -1;
2403 wattrs.cursor = ( bc->refs == NULL ) ? ct_pencil : ct_pointer;
2404 bv->v = GWidgetCreateSubWindow(gw,&pos,v_e_h,bv,&wattrs);
2405 GDrawSetWindowTypeName(bv->v, "BitmapView");
2406
2407 bv->height = pos.height; bv->width = pos.width;
2408 bv->b1_tool = ( bc->refs == NULL ) ? bvt_pencil : bvt_pointer; bv->cb1_tool = bvt_pointer;
2409 bv->b2_tool = bvt_magnify; bv->cb2_tool = bvt_shift;
2410 bv->s1_tool = bv->s2_tool = bv->er_tool = bvt_pointer;
2411 bv->showing_tool = ( bc->refs == NULL ) ? bvt_pencil : bvt_pointer;
2412 bv->pressed_tool = bv->pressed_display = bv->active_tool = bvt_none;
2413
2414 /*bv->tools = BVMakeTools(bv);*/
2415 /*bv->layers = BVMakeLayers(bv);*/
2416
2417 extern GResFont cv_pointnumberfont;
2418 bv->small = cv_pointnumberfont.fi;
2419 GDrawWindowFontMetrics(gw,bv->small,&as,&ds,&ld);
2420 bv->sfh = as+ds; bv->sas = as;
2421
2422 BVFit(bv);
2423 GDrawSetVisible(bv->v,true);
2424 GDrawSetVisible(gw,true);
2425 return( bv );
2426 }
2427
2428 BitmapView *BitmapViewCreatePick(int enc, FontView *fv) {
2429 BDFFont *bdf;
2430 SplineFont *sf;
2431 EncMap *map;
2432
2433 sf = fv->b.cidmaster ? fv->b.cidmaster : fv->b.sf;
2434 map = fv->b.map;
2435
2436 if ( fv->show!=fv->filled )
2437 bdf = fv->show;
2438 else
2439 for ( bdf = sf->bitmaps; bdf!=NULL && bdf->pixelsize!=BVShows.lastpixelsize; bdf = bdf->next );
2440 if ( bdf==NULL )
2441 bdf = sf->bitmaps;
2442
2443 return( BitmapViewCreate(BDFMakeChar(bdf,map,enc),bdf,fv,enc));
2444 }
2445
2446 void BitmapViewFree(BitmapView *bv) {
2447 free(bv);
2448 }
2449
2450 static void BC_RefreshAll(BDFChar *bc) {
2451 BitmapView *bv;
2452
2453 for ( bv = bc->views; bv!=NULL; bv = bv->next )
2454 GDrawRequestExpose(bv->v,NULL,false);
2455 }
2456
2457 static void BC_DestroyAll(BDFChar *bc) {
2458 BitmapView *bv, *next;
2459
2460 for ( bv = bc->views; bv!=NULL; bv=next ) {
2461 next = bv->next;
2462 GDrawDestroyWindow(bv->gw);
2463 }
2464 }
2465
2466 struct bc_interface gdraw_bc_interface = {
2467 BC_CharChangedUpdate,
2468 BC_RefreshAll,
2469 BC_DestroyAll
2470 };