Ejemplo n.º 1
0
void MacDock::overlay(const QString& text)
{
	if (text.isEmpty()) {
		overlayed = false;
		RestoreApplicationDockTileImage();
		return;
	}

	// Create the context
	CGContextRef context = BeginCGContextForApplicationDockTile();

	if (!overlayed) {
		overlayed = true;

		// Add some subtle drop down shadow
		// FIXME: Disabled because 10.2 doesn't support it
		//CGSize s = { 2.0, -4.0 };
		//CGContextSetShadow(context,s,5.0);
	}

	// Draw a circle
	CGContextBeginPath(context);
	CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
	CGContextClosePath(context);
	CGContextSetRGBFillColor(context, 1, 0.0, 0.0, 1);
	CGContextFillPath(context);

	// Set the clipping path to the same circle
	CGContextBeginPath(context);
	CGContextAddArc(context, 95.0, 95.0, 25.0, 0.0, 2 * M_PI, true);
	CGContextClip(context);

	// Remove drop shadow
	// FIXME: Disabled because 10.2 doesn't support it
	//CGSize s = { 0.0, -0.0 };
	//CGContextSetShadowWithColor(context, s, 0, NULL);

	// Select the appropriate font
	CGContextSelectFont(context,DOCK_FONT_NAME, DOCK_FONT_SIZE, kCGEncodingMacRoman);
	CGContextSetRGBFillColor(context, 1, 1, 1, 1);

	// Draw the text invisible
	CGPoint begin = CGContextGetTextPosition(context);
	CGContextSetTextDrawingMode(context, kCGTextInvisible);	
	CGContextShowTextAtPoint(context, begin.x, begin.y, text.toStdString().c_str(), text.length());
	CGPoint end = CGContextGetTextPosition(context);

	// Draw the text
	CGContextSetTextDrawingMode(context, kCGTextFill);	
	CGContextShowTextAtPoint(context, 95 - (end.x - begin.x)/2, 95 - 8, text.toStdString().c_str(), text.length());
	
	// Cleanup
	CGContextFlush(context);
	EndCGContextForApplicationDockTile(context);
}
Ejemplo n.º 2
0
static double 	Quartz_StrWidth(char *str, 
				R_GE_gcontext *gc,
				NewDevDesc *dd)
{
    QuartzDesc *xd = (QuartzDesc*)dd->deviceSpecific;
    CGPoint position;

    CGContextSaveGState( GetContext(xd) );
    CGContextTranslateCTM( GetContext(xd), 0, 0 );

    CGContextScaleCTM( GetContext(xd), -1, 1);

    CGContextRotateCTM( GetContext(xd), -1.0 * 3.1416);

    CGContextSetTextDrawingMode( GetContext(xd), kCGTextInvisible );

    Quartz_SetFont(gc->fontfamily, gc->fontface, gc->cex,  gc->ps, dd);

    CGContextShowTextAtPoint( GetContext(xd), 0, 0, str, strlen(str) );

    position = CGContextGetTextPosition( GetContext(xd) );

    CGContextRestoreGState( GetContext(xd) );
    return(position.x);
}
Ejemplo n.º 3
0
oop CGContextGetTextPosition_wrap(CGContextRef c) {
  CGPoint p = CGContextGetTextPosition(c);
  objVectorOop r = Memory->objVectorObj->cloneSize(2);
  r->obj_at_put(0, as_floatOop(p.x), false);
  r->obj_at_put(1, as_floatOop(p.y), false);
  return r;
}
Ejemplo n.º 4
0
JNIEXPORT void JNICALL OS_NATIVE(CGContextGetTextPosition)
	(JNIEnv *env, jclass that, jint arg0, jobject arg1)
{
	CGPoint _arg1, *lparg1=NULL;
	OS_NATIVE_ENTER(env, that, CGContextGetTextPosition_FUNC)
	if (arg1) if ((lparg1 = getCGPointFields(env, arg1, &_arg1)) == NULL) goto failTag;
	*lparg1 = CGContextGetTextPosition((CGContextRef)arg0);
failTag:
	if (arg1 && lparg1) setCGPointFields(env, arg1, lparg1);
	OS_NATIVE_EXIT(env, that, CGContextGetTextPosition_FUNC)
}
Ejemplo n.º 5
0
static void 	Quartz_MetricInfo(int c, 
				  R_GE_gcontext *gc,
				  double* ascent, double* descent, 
				  double* width,
				  NewDevDesc *dd)
{
    FMetricRec myFMetric;
    QuartzDesc *xd = (QuartzDesc *) dd-> deviceSpecific;
    char testo[2];
	char *ff;
    CGrafPtr savedPort;
    Rect bounds;
    CGPoint position;
	unsigned char tmp;

    testo[0] = c;
    testo[1] = '\0';
/*    fprintf(stderr,"c=%c,>%s<\n",c,testo);
  */  GetPort(&savedPort);

    SetPort(GetWindowPort(xd->window));

    Quartz_SetFont(gc->fontfamily, gc->fontface, gc->cex,  gc->ps, dd);

    if(c==0){
        FontMetrics(&myFMetric);
        *ascent = xd->yscale *floor(gc->cex * gc->ps + 0.5) * FixedToFloat(myFMetric.ascent);
        *descent = xd->yscale*floor(gc->cex * gc->ps + 0.5) * FixedToFloat(myFMetric.descent);
    } else {

    CGContextSaveGState( GetContext(xd) );
    CGContextTranslateCTM( GetContext(xd), 0, 0 );
    CGContextScaleCTM( GetContext(xd), -1, 1);
    CGContextRotateCTM( GetContext(xd), -1.0 * 3.1416);
    CGContextSetTextDrawingMode( GetContext(xd), kCGTextInvisible );

	Quartz_SetFont(gc->fontfamily, gc->fontface, gc->cex,  gc->ps, dd);

	ff = Quartz_TranslateFontFamily(gc->fontfamily, gc->fontface, xd->family);
	tmp = (unsigned char)c;
    if( (gc->fontface == 5) || (strcmp(ff,"Symbol")==0)){
       if( (tmp>31) && IsThisASymbol(tmp))
        testo[0] = (char)Lat2Uni[tmp-31-1];
       else	
		Quartz_SetFont(gc->fontfamily, -1, gc->cex,  gc->ps, dd);
	 } else {
        if(tmp>127)
         testo[0] = (char)Lat2Mac[tmp-127-1];
     }	 

    CGContextShowTextAtPoint( GetContext(xd), 0, 0, testo, 1 );
    
	
    position = CGContextGetTextPosition( GetContext(xd) );
    CGContextRestoreGState( GetContext(xd) );
    
        QDTextBounds(1,testo,&bounds);
        *ascent = -bounds.top;
        *descent = bounds.bottom;
        *width = bounds.right - bounds.left;
        *width = position.x;
    }    
    
    SetPort(savedPort);
/*    fprintf(stderr,"ascent=%f, descent=%f,width=%f\n",*ascent, *descent, *width);
*/
 return;
}
Ejemplo n.º 6
0
void map_text(MapGC *mgc, MapSettings *settings,
	      int x, int y, const char *text, int style)
{
  if (FALSE);
#ifdef HAVE_CAIRO
  else if (mgc->cairo_cr)
    {
      int xpos = x;
      int ypos = y;
      cairo_text_extents_t extents;

      cairo_select_font_face(mgc->cairo_cr, "Sans",
			     CAIRO_FONT_SLANT_NORMAL,
			     CAIRO_FONT_WEIGHT_NORMAL);

      if (style & 0x800)
	{
	  if (settings->pdamode)
	    cairo_set_font_size(mgc->cairo_cr, 9);
	  else
	    cairo_set_font_size(mgc->cairo_cr, 14);
	}
      else
	{
	  if (settings->pdamode)
	    cairo_set_font_size(mgc->cairo_cr, 8);
	  else
	    cairo_set_font_size(mgc->cairo_cr, 11);
	}

      cairo_text_extents(mgc->cairo_cr, text, &extents);

      if ((style & 0x300) == 0x100)
	{
	  xpos -= extents.width;
	}
      else if ((style & 0x300) == 0x200)
	{
	  xpos -= extents.width / 2;
	}
      else if ((style & 0x300) == 0x300)
	{
	  xpos -= extents.width / 2;
	  ypos -= extents.height / 2;
	}

      if (style & 0x400)
	map_bkg_rectangle(mgc, settings,
			  xpos, ypos, extents.width, extents.height);

      if (style & 1)
	cairo_set_source_rgb(mgc->cairo_cr, 0, 0, 1);
      else
	cairo_set_source_rgb(mgc->cairo_cr, 0, 0, 0);

      cairo_move_to(mgc->cairo_cr, xpos, ypos + extents.height);
      cairo_show_text(mgc->cairo_cr, text);
    }
#endif
#ifdef HAVE_GTK
  else if (mgc->gtk_drawable)
    {
      int xpos = x;
      int ypos = y;
      int width;
      int height;

      PangoFontDescription *fd;
      PangoLayout *layout =
	gtk_widget_create_pango_layout(mgc->gtk_widget, text);

      if (style & 0x800)
	{
	  if (settings->pdamode)
	    fd = pango_font_description_from_string("Sans 9");
	  else
	    fd = pango_font_description_from_string("Sans 14");
	}
      else
	{
	  if (settings->pdamode)
	    fd = pango_font_description_from_string("Sans 8");
	  else
	    fd = pango_font_description_from_string("Sans 11");
	}

      pango_layout_set_font_description(layout, fd);

      pango_layout_get_pixel_size(layout, &width, &height);

      if ((style & 0x300) == 0x100)
	{
	  xpos -= width;
	}
      else if ((style & 0x300) == 0x200)
	{
	  xpos -= width / 2;
	}
      else if ((style & 0x300) == 0x300)
	{
	  xpos -= width / 2;
	  ypos -= height / 2;
	}

      if (style & 0x400)
	map_bkg_rectangle(mgc, settings,
			  xpos, ypos, width, height);

      if (style & 1)
	gdk_draw_layout_with_colors(mgc->gtk_drawable, mgc->gtk_gc, xpos, ypos,
				    layout, &settings->blue, NULL);
      else
	gdk_draw_layout_with_colors(mgc->gtk_drawable, mgc->gtk_gc, xpos, ypos,
				    layout, &settings->black, NULL);

      if (layout != NULL)
	g_object_unref(G_OBJECT(layout));

      pango_font_description_free(fd);
    }
#endif
#ifdef HAVE_QT
  else if (mgc->qt_painter)
    {
      qt_text(mgc->qt_painter, settings,
	      x, y, text, style);
    }
#endif
#ifdef HAVE_QUARTZ
  else if (mgc->quartz_gc)
    {
      int xpos = x;
      int ypos = y;
      int width;
      int height;

      CGContextSelectFont(mgc->quartz_gc, "Verdana",
			  8, kCGEncodingMacRoman);

      if (style & 0x800)
	{
	  if (settings->pdamode)
	    CGContextSetFontSize(mgc->quartz_gc, 9);
	  else
	    CGContextSetFontSize(mgc->quartz_gc, 14);
	}
      else
	{
	  if (settings->pdamode)
	    CGContextSetFontSize(mgc->quartz_gc, 8);
	  else
	    CGContextSetFontSize(mgc->quartz_gc, 11);
	}

      {
	CGPoint oldPos = CGContextGetTextPosition(mgc->quartz_gc);
	CGContextSetTextDrawingMode(mgc->quartz_gc, kCGTextInvisible);
	CGContextShowText(mgc->quartz_gc, text, strlen(text));
	CGPoint newPos = CGContextGetTextPosition(mgc->quartz_gc);
	CGContextSetTextDrawingMode(mgc->quartz_gc, kCGTextFill);
	CGContextSetTextPosition(mgc->quartz_gc, oldPos.x, oldPos.y);
	width = newPos.x - oldPos.x;
      }

      if ((style & 0x300) == 0x100)
	{
	  xpos -= width;
	}
      else if ((style & 0x300) == 0x200)
	{
	  xpos -= width / 2;
	}
      else if ((style & 0x300) == 0x300)
	{
	  xpos -= width / 2;
	  ypos -= height / 2;
	}

      if (style & 0x400)
	map_bkg_rectangle(mgc, settings,
			  xpos, ypos, width, height);

      if (style & 1)
	CGContextSetRGBStrokeColor(mgc->quartz_gc, 0, 0, 1, 1);
      else
	CGContextSetRGBStrokeColor(mgc->quartz_gc, 0, 0, 0, 1);

      CGContextSetTextPosition(mgc->quartz_gc, xpos, ypos);
      CGContextShowText(mgc->quartz_gc, text, strlen(text));
    }
#endif
#ifdef WIN32
  else if (mgc->win_dc)
    {
      int xpos = x;
      int ypos = y;
      int fontSize;
      HFONT oldFont;
      HFONT font;
      SIZE textSize;

      if (style & 0x800)
	{
	  if (settings->pdamode)
	    fontSize = 9;
	  else
	    fontSize = 14;
	}
      else
	{
	  if (settings->pdamode)
	    fontSize = 8;
	  else
	    fontSize = 11;
	}

      fontSize = fontSize * 3 / 2;

      font = CreateFont(fontSize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "MSSansSerif");
      oldFont = SelectObject(mgc->win_dc, font);

      GetTextExtentPoint32(mgc->win_dc, text, strlen(text), &textSize);

      if ((style & 0x300) == 0x100)
	{
	  xpos -= textSize.cx;
	}
      else if ((style & 0x300) == 0x200)
	{
	  xpos -= textSize.cx / 2;
	}
      else if ((style & 0x300) == 0x300)
	{
	  xpos -= textSize.cx / 2;
	  ypos -= textSize.cy / 2;
	}

      if (style & 0x400)
	map_bkg_rectangle(mgc, settings,
			  xpos, ypos, textSize.cx, textSize.cy);

      if (style & 1)
	SetTextColor(mgc->win_dc, RGB(0x00, 0x00, 0xff));
      else
	SetTextColor(mgc->win_dc, RGB(0x00, 0x00, 0x00));

      SetBkMode(mgc->win_dc, TRANSPARENT);
      TextOut(mgc->win_dc, xpos, ypos, text, strlen(text));
      SelectObject(mgc->win_dc, oldFont);
      DeleteObject(font);
    }
#endif
}
Ejemplo n.º 7
0
Memsubfont*
mksubfont(XFont *f, char *name, int lo, int hi, int size, int antialias)
{
	CFStringRef s;
	CGColorSpaceRef color;
	CGContextRef ctxt;
	CTFontRef font;
	CTFontDescriptorRef desc;
	CGRect bbox;
	Memimage *m, *mc, *m1;
	int x, y, y0;
	int i, height, ascent;
	Fontchar *fc, *fc0;
	Memsubfont *sf;
	CGFloat whitef[] = { 1.0, 1.0 };
	CGColorRef white;

	s = c2mac(name);
	desc = CTFontDescriptorCreateWithNameAndSize(s, size);
	CFRelease(s);
	if(desc == nil)
		return nil;
	font = CTFontCreateWithFontDescriptor(desc, 0, nil);
	CFRelease(desc);
	if(font == nil)
		return nil;
	
	
	bbox = CTFontGetBoundingBox(font);
	x = (int)(bbox.size.width*2 + 0.99999999);

	fontheight(f, size, &height, &ascent);
	y = height;
	y0 = height - ascent;

	m = allocmemimage(Rect(0, 0, x*(hi+1-lo)+1, y+1), GREY8);
	if(m == nil)
		return nil;
	mc = allocmemimage(Rect(0, 0, x+1, y+1), GREY8);
	if(mc == nil){
		freememimage(m);
		return nil;
	}
	memfillcolor(m, DBlack);
	memfillcolor(mc, DBlack);
	fc = malloc((hi+2 - lo) * sizeof fc[0]);
	sf = malloc(sizeof *sf);
	if(fc == nil || sf == nil) {
		freememimage(m);
		freememimage(mc);
		free(fc);
		free(sf);
		return nil;
	}
	fc0 = fc;

	color = CGColorSpaceCreateWithName(kCGColorSpaceGenericGray);
	ctxt = CGBitmapContextCreate(byteaddr(mc, mc->r.min), Dx(mc->r), Dy(mc->r), 8,
		mc->width*sizeof(u32int), color, kCGImageAlphaNone);
	white = CGColorCreate(color, whitef);
	CGColorSpaceRelease(color);
	if(ctxt == nil) {
		freememimage(m);
		freememimage(mc);
		free(fc);
		free(sf);
		return nil;
	}

	CGContextSetAllowsAntialiasing(ctxt, antialias);
	CGContextSetTextPosition(ctxt, 0, 0);	// XXX
#if OSX_VERSION >= 101400
	CGContextSetAllowsFontSmoothing(ctxt, false);
#endif

	x = 0;
	for(i=lo; i<=hi; i++, fc++) {
		char buf[20];
		CFStringRef str;
		CFDictionaryRef attrs;
		CFAttributedStringRef attrString;
		CTLineRef line;
		CGRect r;
		CGPoint p1;
		CFStringRef keys[] = { kCTFontAttributeName, kCTForegroundColorAttributeName };
		CFTypeRef values[] = { font, white };

		sprint(buf, "%C", (Rune)mapUnicode(name, i));
 		str = c2mac(buf);
 		
 		// See https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/CoreText_Programming/LayoutOperations/LayoutOperations.html#//apple_ref/doc/uid/TP40005533-CH12-SW2
 		attrs = CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
			(const void**)&values, sizeof(keys) / sizeof(keys[0]),
			&kCFTypeDictionaryKeyCallBacks,
			&kCFTypeDictionaryValueCallBacks);
		attrString = CFAttributedStringCreate(kCFAllocatorDefault, str, attrs);
		CFRelease(str);
		CFRelease(attrs);

		line = CTLineCreateWithAttributedString(attrString);
		CGContextSetTextPosition(ctxt, 0, y0);
		r = CTLineGetImageBounds(line, ctxt);
		memfillcolor(mc, DBlack);
		CTLineDraw(line, ctxt);		
		CFRelease(line);

		fc->x = x;
		fc->top = 0;
		fc->bottom = Dy(m->r);

//		fprint(2, "printed %#x: %g %g\n", mapUnicode(i), p1.x, p1.y);
		p1 = CGContextGetTextPosition(ctxt);
		if(p1.x <= 0 || mapUnicode(name, i) == 0xfffd) {
			fc->width = 0;
			fc->left = 0;
			if(i == 0) {
				drawpjw(m, fc, x, (int)(bbox.size.width + 0.99999999), y, y - y0);
				x += fc->width;
			}	
			continue;
		}

		memimagedraw(m, Rect(x, 0, x + p1.x, y), mc, ZP, memopaque, ZP, S);
		fc->width = p1.x;
		fc->left = 0;
		x += p1.x;
	}
	fc->x = x;

	// round up to 32-bit boundary
	// so that in-memory data is same
	// layout as in-file data.
	if(x == 0)
		x = 1;
	if(y == 0)
		y = 1;
	if(antialias)
		x += -x & 3;
	else
		x += -x & 31;
	m1 = allocmemimage(Rect(0, 0, x, y), antialias ? GREY8 : GREY1);
	memimagedraw(m1, m1->r, m, m->r.min, memopaque, ZP, S);
	freememimage(m);
	freememimage(mc);

	sf->name = nil;
	sf->n = hi+1 - lo;
	sf->height = Dy(m1->r);
	sf->ascent = Dy(m1->r) - y0;
	sf->info = fc0;
	sf->bits = m1;
	
	return sf;
}