Example #1
0
int4 MCScreenDC::textwidth(MCFontStruct *f, const char *s, uint2 len, bool p_unicode_override)
{
    if (len == 0)
        return 0;
    if (f->unicode || p_unicode_override)
    {
        if (MCmajorosversion >= 0x1050)
        {
            return OSX_DrawUnicodeText(0, 0, s, len, f, false, true);
        }
        else
        {
            int4 fwidth;
            short oldfid = GetPortTextFont(GetQDGlobalsThePort());
            short oldsize = GetPortTextSize(GetQDGlobalsThePort());
            short oldstyle = GetPortTextFace(GetQDGlobalsThePort());
            TextFont((short)(intptr_t)f->fid);
            TextSize(f->size);
            TextFace(f->style);


            SInt16  baseline;
            CFStringRef cfstring;

            char *tempbuffer = NULL;


            if (len)
            {
                uint2 *testchar = (uint2 *)s;
                if (testchar[(len - 2 )>> 1] == 12398)
                {
                    tempbuffer = new char[len+2];
                    memcpy(tempbuffer,s,len);
                    uint2 *tchar = (uint2 *)&tempbuffer[len];
                    *tchar = 0;
                }
            }


            cfstring = CFStringCreateWithCharactersNoCopy(NULL, (UniChar *)(tempbuffer != NULL? tempbuffer: s), (tempbuffer != NULL? len + 2:len) >> 1,
                       kCFAllocatorNull);
            Point dimensions = {0, 0};
            GetThemeTextDimensions(cfstring, kThemeCurrentPortFont, kThemeStateActive, false, &dimensions, &baseline);
            fwidth = dimensions.h;
            CFRelease(cfstring);
            if (tempbuffer)
                delete tempbuffer;

            TextFont(oldfid);
            TextSize(oldsize);
            TextFace(oldstyle);
            return fwidth;
        }
    }
    else
    {
        // MW-2012-09-21: [[ Bug 3884 ]] If the font is wide, measure using OS routine.
        if (f -> wide)
void GetFont(
	TextSpec *spec)
{
	GrafPtr port;

	GetPort(&port);
	spec->font=GetPortTextFont(port);
	spec->style=GetPortTextFace(port);
	spec->size=GetPortTextSize(port);
}
Example #3
0
void SaveQDDrawingState( QDDrawingState *ioDrawingState, const Boolean inSaveTextState )
{	GWorldPtr		tempWorld;
	GDHandle		tempDevice;

	Assert( ioDrawingState != nil );

	// Get the current GWorld, so I can access it's fields.
	GetGWorld( &tempWorld, &tempDevice );

	// Get the background state.
	GetBackColor( &ioDrawingState->backColor );
/*#if !( defined( TARGET_API_MAC_CARBON ) && ( TARGET_API_MAC_CARBON == 1 ) )
	if ( tempWorld->bkPixPat == nil )
		ioDrawingState->backPixPatH = nil;
	else
#endif
		ioDrawingState->backPixPatH = NewPixPat( );

	if ( ioDrawingState->backPixPatH != nil )
		GetPortBackPixPat( tempWorld, ioDrawingState->backPixPatH );
*/
	// Get the pen/foreground state.
	GetForeColor( &ioDrawingState->foreColor );
/*#if !( defined( TARGET_API_MAC_CARBON ) && ( TARGET_API_MAC_CARBON == 1 ) )
	if ( tempWorld->pnPixPat == nil )
		ioDrawingState->penPixPatH = nil;
	else
#endif
		ioDrawingState->penPixPatH = NewPixPat( );

	if ( ioDrawingState->penPixPatH != nil )
		GetPortPenPixPat( tempWorld, ioDrawingState->penPixPatH );
*/
	GetPenState( &ioDrawingState->penState );

	// Optionally save the text font, face, size and mode.
	ioDrawingState->haveTextState = inSaveTextState;
	if ( inSaveTextState ) {
		ioDrawingState->textStyle.tsFont = GetPortTextFont( tempWorld );
		ioDrawingState->textStyle.tsFace = GetPortTextFace( tempWorld );
		ioDrawingState->textStyle.tsSize = GetPortTextSize( tempWorld );
		ioDrawingState->textMode = GetPortTextMode( tempWorld );
	}

#if ALIST_USEAPPEARANCEMGR && TARGET_RT_MAC_CFM
	// If we're running under CFM and have Appearance Mgr 1.1 or later, use the ThemeDrawingState routines.
	if ( local_AppearanceMgrVersion( ) > 0x0110 )
		ioDrawingState->haveThemeState = ( GetThemeDrawingState( &ioDrawingState->themeState ) == noErr );
	else {
		ioDrawingState->haveThemeState = false;
		ioDrawingState->themeState = nil;
	}
#endif
}
Example #4
0
// --------------------------------------------------------------------------------------
static void drawIconListCell(ListHandle theList, const Rect *cellRect, 
								IconListCellDataRec *theCellData, Boolean selected)
{
	GrafPtr savedPort;
	CGrafPtr listPort;
	ThemeDrawingState savedState;
	Boolean active;
	Rect iconRect, textRect;
	short savedFont, savedSize;
	Style savedFace;
	CFStringRef cellName;
	
	GetPort(&savedPort);
	listPort = GetListPort(theList);
	SetPort((GrafPtr)listPort);
	
	GetThemeDrawingState(&savedState);
	
	if (selected)						// we don't need to change the background 
	{									// color if this Cell isn't highlighted
		Pattern whitePattern;
		RGBColor highlightColor;
		
		GetQDGlobalsWhite(&whitePattern);	// set the background pattern so that 
		BackPat(&whitePattern);				// the color is properly set as a solid color
		
		LMGetHiliteRGB(&highlightColor);
		RGBBackColor(&highlightColor);		// set the background to the highlight color
	}
	
	EraseRect(cellRect);
	
	calculateDrawingBounds(cellRect, &iconRect, &textRect);	// get the drawing Rects
	active = GetListActive(theList);
	
		// draw the IconRef using Icon Services
	PlotIconRef(&iconRect, kAlignNone, active ? kTransformNone : kTransformDisabled, 
				kIconServicesNormalUsageFlag, theCellData->icon);
	
#if TARGET_API_MAC_OS8		// draw TextEdit text in Classic
#pragma unused (cellName)
	savedFont = GetPortTextFont(listPort);	// Get/SetThemeDrawingState doesn't save or 
	savedFace = GetPortTextFace(listPort);	// restore these
	savedSize = GetPortTextSize(listPort);
	
	UseThemeFont(kThemeViewsFont, smCurrentScript);
	TETextBox(&theCellData->name[1], theCellData->name[0], &textRect, teCenter);
	
	TextFont(savedFont);
	TextFace(savedFace);
	TextSize(savedSize);
#else						// draw Appearance text in Carbon
#pragma unused (savedFont, savedSize, savedFace)
	cellName = CFStringCreateWithPascalString(kCFAllocatorDefault, theCellData->name, 
												GetApplicationTextEncoding());
	DrawThemeTextBox(cellName, kThemeViewsFont, 
						active ? kThemeStateActive : kThemeStateInactive, true, 
						&textRect, teCenter, NULL);
	CFRelease(cellName);
#endif
	
	SetThemeDrawingState(savedState, true);
	SetPort(savedPort);
} // drawIconListCell
Example #5
0
            TextFont(oldfid);
            TextSize(oldsize);
            TextFace(oldstyle);
            return fwidth;
        }
    }
    else
    {
        // MW-2012-09-21: [[ Bug 3884 ]] If the font is wide, measure using OS routine.
        if (f -> wide)
        {
            int4 fwidth;
            short oldfid = GetPortTextFont(GetQDGlobalsThePort());
            short oldsize = GetPortTextSize(GetQDGlobalsThePort());
            short oldstyle = GetPortTextFace(GetQDGlobalsThePort());
            TextFont((short)(intptr_t)f->fid);
            TextSize(f->size);
            TextFace(f->style);

            fwidth = TextWidth(s, 0, len);

            TextFont(oldfid);
            TextSize(oldsize);
            TextFace(oldstyle);
            return fwidth;
        }
        else
        {
            int4 iwidth = 0;
            while (len--)
Example #6
0
static
void draw_string(int x, int y, int width, int height, Str255 chars)
{
  FontInfo info;
  GWorldPtr fromworld, toworld;
  CGrafPtr onport, saveport;
  GDHandle savedevice;
  int txFont, txFace, txSize;
  Rect fromrect, torect, onrect;
  PixMapHandle frompix, topix, onpix;
  int *from, *to, from_width, to_width;
  register int descent, w = 0, h = 0;
  register int i, j, ii = 0, jj = 0;

  if (p->path != 0)
    {
      GetFontInfo(&info);
      height += 8;
      descent = info.descent;

      switch (p->path)
	{
	  case 1: x -= height-descent; y -= width; w = height; h = width; break;
	  case 2: x -= width; y -= descent; w = width; h = height; break;
	  case 3: x -= descent; w = height; h = width; break;
	}

      GetGWorld(&saveport, &savedevice);
      txFont = GetPortTextFont(saveport);
      txFace = GetPortTextFace(saveport);
      txSize = GetPortTextSize(saveport);

      onport = p->port;
      onpix = GetPortPixMap(onport);

      fromrect.left = 0;
      fromrect.right = width;
      fromrect.top = 0;
      fromrect.bottom = height;
      NewGWorld(&fromworld, 32, &fromrect, NULL, NULL, 0);
      SetGWorld(fromworld, NULL);
	
      frompix = GetGWorldPixMap(fromworld);
      from = (int *) GetPixBaseAddr(frompix);
      from_width = GetPixRowBytes(frompix) / 4;

      LockPixels(frompix);

      EraseRect(&fromrect);
      MoveTo(0, height - descent);
      TextFont(txFont);
      TextFace(txFace);
      TextSize(txSize);
      DrawString(chars);

      torect.left = 0;
      torect.right = w;
      torect.top = 0;
      torect.bottom = h;
      NewGWorld(&toworld, 32, &torect, NULL, NULL, 0);

      topix = GetGWorldPixMap(toworld);
      to = (int *) GetPixBaseAddr(topix);
      to_width = GetPixRowBytes(topix) / 4;

      LockPixels(topix);
      for (i = 0; i < width; i++)
	{
	  for (j = 0; j < height; j++)
	    {
	      switch (p->path)
		{
		  case 1: ii = j; jj = h - i - 1; break;
		  case 2: ii = w - i - 1; jj = h - j - 1; break;
		  case 3: ii = w - j - 1; jj = i; break;
		}
	      to[jj * to_width + ii] = from[j * from_width + i];
	    }
	}
      UnlockPixels(topix);
      UnlockPixels(frompix);

      onrect.left = x;
      onrect.right = x + w;
      onrect.top = y;
      onrect.bottom = y + h;

      SetGWorld(saveport, savedevice);

      SetPort(onport);
      LockPixels(topix);
      CopyBits(
	(BitMap *) *topix, (BitMap *) *onpix, &torect, &onrect, srcOr, NULL);
      UnlockPixels(topix);
	
      DisposeGWorld(toworld);
      DisposeGWorld(fromworld);
    }
  else
    {
      MoveTo(x, y);
      DrawString(chars);
    }
}