Subversion Repositories filter_foundry

Rev

Rev 193 | Rev 268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.         This file is part of a common library
  3.     Copyright (C) 1990-2006 Toby Thain, toby@telegraphics.com.au
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by  
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License  
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18. */
  19.  
  20. #include <quickdraw.h>
  21. #include <fonts.h>
  22. #include <gestalt.h>
  23. #include <stdlib.h> // abs()
  24.  
  25. #include "qd.h"
  26. #include "misc-mac.h"
  27.  
  28.  
  29. #if ! TARGET_API_MAC_CARBON
  30. #ifndef __MWERKS__
  31.         QDGlobals qd;
  32. #endif
  33. #endif
  34.  
  35. #if !OPAQUE_TOOLBOX_STRUCTS
  36. void decompose_region(RgnHandle rgn,void (*func)(Rect*)){
  37.         enum{FLAG=32767};
  38.         Boolean f;
  39.         short *p,*q,*r,*l1,*l2,*t,list1[100],list2[100],last_top,cur_top;
  40.         RgnHandle temp_rgn;
  41.        
  42.         CopyRgn(rgn,temp_rgn = NewRgn());
  43.         f = true;
  44.         l1 = list1;
  45.         l2 = list2;
  46.         HLock((Handle)temp_rgn);
  47.         if(GetHandleSize((Handle)temp_rgn) == sizeof(Region))
  48.                 (*func)(&(*temp_rgn)->rgnBBox);
  49.         else
  50.                 for(p=(short*)((char*)*temp_rgn+sizeof(Region));*p != FLAG;){
  51.                         cur_top = *p++;
  52.                         if(f){
  53.                                 f = false;
  54.                                 q = l1;
  55.                                 while((*q++ = *p++)!=FLAG)
  56.                                         ;
  57.                         }else{ Rect rct;
  58.                                 rct.top = last_top;
  59.                                 rct.bottom = cur_top;
  60.                                 for(q = l1;*q != FLAG;q += 2){
  61.                                         rct.left = q[0];
  62.                                         rct.right = q[1];
  63.                                         (*func)(&rct);
  64.                                 }
  65.                                
  66.                                 q = l1;
  67.                                 r = l2;
  68.                                 for(;;)
  69.                                         if(*q<*p)
  70.                                                 *r++ = *q++;
  71.                                         else if(*q>*p)
  72.                                                 *r++ = *p++;
  73.                                         else if(*p++ == FLAG){
  74.                                                 *r = FLAG;
  75.                                                 break;
  76.                                         }else q++;
  77.                        
  78.                                 t = l1;
  79.                                 l1 = l2;
  80.                                 l2 = t;
  81.                         }
  82.                         last_top = cur_top;
  83.                 }
  84.         DisposeRgn(temp_rgn);
  85. }
  86. #endif
  87.  
  88. Fixed fractional_width(unsigned char *s){
  89.         FMetricRec theMetrics;
  90.         Fixed *t,w;
  91.  
  92.         FontMetrics(&theMetrics);
  93.         t = ((WidthTable*)*theMetrics.wTabHandle)->tabData;
  94.         for(w=0;*s;)
  95.                 w += t[*s++];
  96.         return w;
  97. }
  98.  
  99. void rect2g(Rect *r){
  100.         LocalToGlobal(&TOPLEFT(*r));
  101.         LocalToGlobal(&BOTRIGHT(*r));
  102. }
  103.  
  104. void rgn2g(RgnHandle rgn){ Point o = {0,0};
  105.         LocalToGlobal(&o);
  106.         OffsetRgn(rgn,o.h,o.v);
  107. }
  108.  
  109. void dashed_lineto(short h,short v){
  110.         PenState ps;
  111.         static Pattern p[] = {{0,255,0,255,0,255,0,255},{170,170,170,170,170,170,170,170}};
  112.  
  113.         GetPenState(&ps);
  114.         PenPat(&p[(abs(ps.pnLoc.h - h) > abs(ps.pnLoc.v - v))]);
  115.         LineTo(h,v);
  116.         SetPenState(&ps);
  117.         MoveTo(h,v);
  118. }
  119.  
  120. Boolean only_greys(CTabHandle ct){ ColorSpec *cs; long i;
  121.         for(i=(*ct)->ctSize+1,cs=(*ct)->ctTable;i--;cs++)
  122.                 if(cs->rgb.red != cs->rgb.green || cs->rgb.green != cs->rgb.blue)
  123.                         return false;
  124.         return true;
  125. }
  126.  
  127. Boolean has_colour_QD(void){
  128. //      SysEnvRec w;
  129. //      return !SysEnvirons(curSysEnvVers,&w) && w.hasColorQD; // works without Gestalt
  130.         return gestalt_attr(gestaltQuickdrawFeatures,gestaltHasColor);
  131. }
  132.