void gdk_draw_segments (GdkDrawable *drawable, GdkGC *gc, GdkSegment *segs, gint nsegs) { int i; gi_point_t pts[2]; PRINTFILE("gdk_draw_segments"); // not used by any exists widget if (nsegs <= 0) return; g_return_if_fail (drawable != NULL); g_return_if_fail (segs != NULL); g_return_if_fail (gc != NULL); if(GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); for (i = 0; i < nsegs; i++) { pts[0].x = segs[i].x1; pts[0].y = segs[i].y1; pts[1].x = segs[i].x2; pts[1].y = segs[i].y2; gi_draw_lines( GDK_GC_XGC (gc), pts,2); } }
void gdk_draw_rectangle (GdkDrawable *drawable, GdkGC *gc, gint filled, gint x, gint y, gint width, gint height) { g_return_if_fail (drawable != NULL); g_return_if_fail (gc != NULL); if (GDK_DRAWABLE_DESTROYED(drawable)) return; if (width == -1) width = ((GdkWindowPrivate*)drawable)->width; if (height == -1) height = ((GdkWindowPrivate*)drawable)->height; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); if (filled){ gi_fill_rect( GDK_GC_XGC(gc), x, y, width, height); } else gi_draw_rect(GDK_GC_XGC(gc),x,y,width,height); //For some reason, nano-X draw wider and higher }
void gdk_draw_lines (GdkDrawable *drawable, GdkGC *gc, GdkPoint *points, gint npoints) { gi_point_t *nanoPoints; gint i; PRINTFILE("gdk_draw_lines"); // only used by gtkctree widget if (npoints <= 0) return; g_return_if_fail (drawable != NULL); g_return_if_fail (points != NULL); g_return_if_fail (gc != NULL); if(GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); nanoPoints = g_new(gi_point_t,npoints); for (i=0;i<npoints;i++) { nanoPoints[i].x = points[i].x; nanoPoints[i].y = points[i].y; } gi_draw_lines( GDK_GC_XGC(gc), npoints, nanoPoints); g_free(nanoPoints); }
void gdk_draw_point (GdkDrawable *drawable, GdkGC *gc, gint x, gint y) { g_return_if_fail (drawable != NULL); g_return_if_fail (gc != NULL); gi_point_t tmp_points[1]; if (GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); //GrPoint (GDK_DRAWABLE_XID(drawable), GDK_GC_XGC(gc), x, y); tmp_points[0].x =x; tmp_points[0].y = y; gi_draw_points ( GDK_GC_XGC (gc), tmp_points, 1); }
void gdk_draw_points (GdkDrawable *drawable, GdkGC *gc, GdkPoint *points, gint npoints) { gi_point_t *nanoPoints; guint i; g_return_if_fail (drawable != NULL); g_return_if_fail ((points != NULL) && (npoints > 0)); g_return_if_fail (gc != NULL); if (GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); nanoPoints = g_new(gi_point_t,npoints); // GdkPoint (gint16) to gi_point_t (int) for (i=0;i<npoints;i++) { nanoPoints[i].x = points[i].x; nanoPoints[i].y = points[i].y; } gi_draw_points(GDK_GC_XGC(gc), npoints, nanoPoints); g_free(nanoPoints); }
/* gdk_draw_text * * Modified by Li-Da Lho to draw 16 bits and Multibyte strings * * Interface changed: add "GdkFont *font" to specify font or fontset explicitely */ void gdk_draw_text (GdkDrawable *drawable, GdkFont *font, GdkGC *gc, gint x, gint y, const gchar *text, gint text_length) { GR_FONT_INFO fid; g_return_if_fail (drawable != NULL); g_return_if_fail (font != NULL); g_return_if_fail (gc != NULL); g_return_if_fail (text!= NULL); gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); //printf("fontid is %d at %d\n", ((GdkFontPrivate*)font)->fid, GDK_GC_XGC(gc)); //GrGetFontInfo(((GdkFontPrivate*)font)->fid, &fid); //GrSetGCUseBackground(GDK_GC_XGC(gc), FALSE); int r,g,b; gi_pixel_to_color(&gdk_screen_info,GDK_GC_XGC(gc)->values.foreground,&r, &g,&b); gi_ufont_set_text_attr(GDK_GC_XGC(gc),GDK_FONT_XFONT(font),FALSE,GI_RGB(r,g,b),0); //dpp, fixme gi_ufont_draw(GDK_GC_XGC(gc),GDK_FONT_XFONT(font),text, x,y,text_length); //GrSetGCFont(GDK_GC_XGC(gc), ((GdkFontPrivate*)font)->fid); /* [00/08/30] @@@ NANOGTK: begin modification @@@ */ //GrText(GDK_DRAWABLE_XID(drawable), GDK_GC_XGC (gc), x, y, text, text_length); /* [00/08/30] @@@ NANOGTK: end modification @@@ */ }
void gdk_draw_text_wc (GdkDrawable *drawable, GdkFont *font, GdkGC *gc, gint x, gint y, const GdkWChar *text, gint text_length) { g_return_if_fail (drawable != NULL); g_return_if_fail (font != NULL); g_return_if_fail (gc != NULL); g_return_if_fail (text!= NULL); //GrSetGCUseBackground(GDK_GC_XGC(gc), FALSE); //fixme GDK_GC_XGC(gc)->values.font = GDK_FONT_XFONT(font); //GrSetGCFont(GDK_GC_XGC(gc), ((GdkFontPrivate*)font)->fid); /* [00/08/30] @@@ NANOGTK: begin modification @@@ */ //GrText (GDK_DRAWABLE_XID(drawable), GDK_GC_XGC (gc), // x, y, text, text_length, GR_TFUC32|GR_TFBASELINE); { gchar* mstr; GdkWChar* str; gint i; str = g_new(GdkWChar, text_length + 1); for (i = 0; i < text_length; i++) { str[i] = text[i]; } str[i] = 0; mstr = gdk_wcstombs(str); gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); //GrText (GDK_DRAWABLE_XID(drawable), GDK_GC_XGC (gc), // x, y, mstr, strlen(mstr)); int r,g,b; gi_pixel_to_color(&gdk_screen_info,GDK_GC_XGC(gc)->values.foreground,&r, &g,&b); gi_ufont_set_text_attr(GDK_GC_XGC(gc),GDK_FONT_XFONT(font),FALSE,GI_RGB(r,g,b),0); // gi_ufont_draw(GDK_GC_XGC(gc),GDK_FONT_XFONT(font),mstr, x,y,strlen(mstr)); g_free(str); g_free(mstr); } /* [00/08/30] @@@ NANOGTK: end modification @@@ */ }
static void gdk_gc_x11_finalize (GObject *object) { GdkGCX11 *x11_gc = GDK_GC_X11 (object); XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc)); G_OBJECT_CLASS (_gdk_gc_x11_parent_class)->finalize (object); }
void gdk_draw_line (GdkDrawable *drawable, GdkGC *gc, gint x1, gint y1, gint x2, gint y2) { g_return_if_fail (drawable != NULL); g_return_if_fail (gc != NULL); if( GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); gi_draw_line(GDK_GC_XGC(gc),x1,y1,x2,y2); }
void gdk_draw_arc (GdkDrawable *drawable, GdkGC *gc, gint filled, gint x, gint y, gint width, gint height, gint angle1, gint angle2) { g_return_if_fail (drawable != NULL); g_return_if_fail (gc != NULL); PRINTFILE("gdk_draw_arc"); // only used by gtkctree widget if (GDK_DRAWABLE_DESTROYED(drawable)) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); if (width == -1) width = ((GdkWindowPrivate*)drawable)->width; if (height == -1) height = ((GdkWindowPrivate*)drawable)->height; if (filled) { gi_fill_arc(GDK_DRAWABLE_XID(drawable),GDK_GC_XGC(gc), x, y, width, height, angle1, angle2); } else{ gi_draw_arc(GDK_DRAWABLE_XID(drawable),GDK_GC_XGC(gc), x, y, width, height, angle1, angle2); } //GrArcAngle(GDK_DRAWABLE_XID(drawable), GDK_GC_XGC(gc), x, y, // width, height, angle1, angle2, filled); }
/* * auto-close the points if the last point not equal to first point */ void gdk_draw_polygon (GdkDrawable *drawable, GdkGC *gc, gint filled, GdkPoint *points, gint npoints) { GdkWindowPrivate *drawable_private; GdkGCPrivate *gc_private; gi_point_t * nanoPoints; gint nano_npoints = npoints; int i; g_return_if_fail (drawable != NULL); g_return_if_fail (gc != NULL); drawable_private = (GdkWindowPrivate*) drawable; if (drawable_private->destroyed) return; gi_gc_attch_window(GDK_GC_XGC(gc), GDK_DRAWABLE_XID(drawable)); gc_private = (GdkGCPrivate*) gc; if (points[npoints-1].x != points[0].x || points[npoints-1].y != points[0].y) nano_npoints = npoints + 1; nanoPoints = g_new(gi_point_t, nano_npoints); // GdkPoint (gint16) to gi_point_t (int) for (i=0;i<npoints;i++) { nanoPoints[i].x = points[i].x; nanoPoints[i].y = points[i].y; } if (nano_npoints > npoints) { nanoPoints[npoints].x = points[0].x; nanoPoints[npoints].y = points[0].y; } if (filled) { gi_fill_polygon ( gc_private->xgc, nano_npoints, nanoPoints,GI_SHAPE_Complex, GI_POLY_CoordOrigin); } else { gi_draw_lines ( gc_private->xgc, nano_npoints, nanoPoints); } g_free(nanoPoints); }
gint nsFreeTypeXImage::DrawString(nsRenderingContextGTK* aContext, nsDrawingSurfaceGTK* aSurface, nscoord aX, nscoord aY, const PRUnichar* aString, PRUint32 aLength) { #if DEBUG_SHOW_GLYPH_BOX PRUint32 x, y; // grey shows image size // red shows character cells // green box shows text ink #endif if (aLength < 1) { return 0; } // get the face/size from the FreeType cache FT_Face face = getFTFace(); NS_ASSERTION(face, "failed to get face/size"); if (!face) return 0; nsresult rslt; PRInt32 leftBearing, rightBearing, ascent, descent, width; rslt = doGetBoundingMetrics(aString, aLength, &leftBearing, &rightBearing, &ascent, &descent, &width); if (NS_FAILED(rslt)) return 0; // make sure we bring down enough background for blending rightBearing = PR_MAX(rightBearing, width+1); // offset in the ximage to the x origin PRInt32 x_origin = PR_MAX(0, -leftBearing); // offset in the ximage to the x origin PRInt32 y_origin = ascent; PRInt32 x_pos = x_origin; int image_width = x_origin + rightBearing; int image_height = y_origin + PR_MAX(descent, 0); if ((image_width<=0) || (image_height<=0)) { // if we do not have any pixels then no point in trying to draw // eg: the space char has 0 height NS_ASSERTION(width>=0, "Negative width"); return width; } Display *dpy = GDK_DISPLAY(); Drawable win = GDK_WINDOW_XWINDOW(aSurface->GetDrawable()); GC gc = GDK_GC_XGC(aContext->GetGC()); XGCValues values; if (!XGetGCValues(dpy, gc, GCForeground, &values)) { NS_ERROR("failed to get foreground pixel"); return 0; } nscolor color = nsX11AlphaBlend::PixelToNSColor(values.foreground); #if DEBUG_SHOW_GLYPH_BOX // show X/Y origin XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-2, aY, aX+2, aY); XDrawLine(dpy, win, DefaultGC(dpy, 0), aX, aY-2, aX, aY+2); // show width XDrawLine(dpy, win, DefaultGC(dpy, 0), aX-x_origin, aY-y_origin-2, aX+rightBearing, aY-y_origin-2); #endif // // Get the background // XImage *sub_image = nsX11AlphaBlend::GetBackground(dpy, DefaultScreen(dpy), win, aX-x_origin, aY-y_origin, image_width, image_height); if (sub_image==nsnull) { #ifdef DEBUG int screen = DefaultScreen(dpy); // complain if the requested area is not completely off screen int win_width = DisplayWidth(dpy, screen); int win_height = DisplayHeight(dpy, screen); if (((int)(aX-leftBearing+image_width) > 0) // not hidden to left && ((int)(aX-leftBearing) < win_width) // not hidden to right && ((int)(aY-ascent+image_height) > 0)// not hidden to top && ((int)(aY-ascent) < win_height)) // not hidden to bottom { NS_ASSERTION(sub_image, "failed to get the image"); } #endif return 0; } #if DEBUG_SHOW_GLYPH_BOX DEBUG_AADRAWBOX(sub_image,0,0,image_width,image_height,0,0,0,255/4); nscolor black NS_RGB(0,255,0); blendPixel blendPixelFunc = nsX11AlphaBlend::GetBlendPixel(); // x origin for (x=0; x<(unsigned int)image_height; x++) if (x%4==0) (*blendPixelFunc)(sub_image, x_origin, x, black, 255/2); // y origin for (y=0; y<(unsigned int)image_width; y++) if (y%4==0) (*blendPixelFunc)(sub_image, y, ascent-1, black, 255/2); #endif FTC_Image_Cache icache; mFt2->GetImageCache(&icache); if (!icache) return 0; // // Get aa glyphs and blend with background // blendGlyph blendGlyph = nsX11AlphaBlend::GetBlendGlyph(); PRUint32 i, extraSurrogateLength; for (i=0; i<aLength; i+=1+extraSurrogateLength) { FT_UInt glyph_index; FT_Glyph glyph; nsresult rv; FT_BBox glyph_bbox; FT_ULong code_point = aString[i]; extraSurrogateLength = 0; if(i<aLength-1 && IS_HIGH_SURROGATE(code_point) && IS_LOW_SURROGATE(aString[i+1])) { // if surrogate, make UCS4 code point from high aString[i] surrogate and // low surrogate aString[i+1] code_point = SURROGATE_TO_UCS4(code_point, aString[i+1]); // skip aString[i+1], it is already used as low surrogate extraSurrogateLength = 1; } mFt2->GetCharIndex(face, code_point, &glyph_index); if (glyph_index) { rv = mFt2->ImageCacheLookup(icache, &mImageDesc, glyph_index, &glyph); } if ((glyph_index) && (NS_SUCCEEDED(rv))) { mFt2->GlyphGetCBox(glyph, ft_glyph_bbox_pixels, &glyph_bbox); } else { // draw an empty box for the missing glyphs GetFallbackGlyphMetrics(&glyph_bbox, face); int x, y, w = glyph_bbox.xMax, h = glyph_bbox.yMax; for (x=1; x<w; x++) { XPutPixel(sub_image, x_pos+x, ascent-1, values.foreground); XPutPixel(sub_image, x_pos+x, ascent-h, values.foreground); } for (y=1; y<h; y++) { XPutPixel(sub_image, x_pos+1, ascent-y, values.foreground); XPutPixel(sub_image, x_pos+w-1, ascent-y, values.foreground); x = (y*(w-2))/h; XPutPixel(sub_image, x_pos+x+1, ascent-y, values.foreground); } x_pos += w + 1; continue; } FT_BitmapGlyph slot = (FT_BitmapGlyph)glyph; nsAntiAliasedGlyph aaglyph(glyph_bbox.xMax-glyph_bbox.xMin, glyph_bbox.yMax-glyph_bbox.yMin, 0); PRUint8 buf[IMAGE_BUFFER_SIZE]; // try to use the stack for data if (!aaglyph.WrapFreeType(&glyph_bbox, slot, buf, IMAGE_BUFFER_SIZE)) { NS_ERROR("failed to wrap freetype image"); XDestroyImage(sub_image); return 0; } // // blend the aa-glyph onto the background // NS_ASSERTION(ascent>=glyph_bbox.yMax,"glyph too tall"); NS_ASSERTION(x_pos>=-aaglyph.GetLBearing(),"glyph extends too far to left"); #if DEBUG_SHOW_GLYPH_BOX // draw box around part of glyph that extends to the left // of the main area (negative LBearing) if (aaglyph.GetLBearing() < 0) { DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetLBearing(), ascent-glyph_bbox.yMax, -aaglyph.GetLBearing(), glyph_bbox.yMax, 255,0,0, 255/4); } // draw box around main glyph area DEBUG_AADRAWBOX(sub_image, x_pos, ascent-glyph_bbox.yMax, aaglyph.GetAdvance(), glyph_bbox.yMax, 0,255,0, 255/4); // draw box around part of glyph that extends to the right // of the main area (negative LBearing) if (aaglyph.GetRBearing() > (int)aaglyph.GetAdvance()) { DEBUG_AADRAWBOX(sub_image, x_pos + aaglyph.GetAdvance(), ascent-glyph_bbox.yMax, aaglyph.GetRBearing()-aaglyph.GetAdvance(), glyph_bbox.yMax, 0,0,255, 255/4); } #endif (*blendGlyph)(sub_image, &aaglyph, sLinearWeightTable, color, x_pos + aaglyph.GetLBearing(), ascent-glyph_bbox.yMax); x_pos += aaglyph.GetAdvance(); } // // Send it to the display // XPutImage(dpy, win, gc, sub_image, 0, 0, aX-x_origin , aY-ascent, image_width, image_height); XDestroyImage(sub_image); return width; }
void my_gdk_draw_text(GdkDrawable *drawable, GdkFont *font, GdkGC *gc, gint x, gint y, const gchar *text, gint text_length) { #ifdef MOZ_WIDGET_GTK GdkWindowPrivate *drawable_private; GdkFontPrivate *font_private; GdkGCPrivate *gc_private; #endif /* MOZ_WIDGET_GTK */ g_return_if_fail (drawable != NULL); g_return_if_fail (font != NULL); g_return_if_fail (gc != NULL); g_return_if_fail (text != NULL); #ifdef MOZ_WIDGET_GTK drawable_private = (GdkWindowPrivate*) drawable; if (drawable_private->destroyed) return; gc_private = (GdkGCPrivate*) gc; font_private = (GdkFontPrivate*) font; #endif /* MOZ_WIDGET_GTK */ #ifdef MOZ_WIDGET_GTK2 if (GDK_IS_WINDOW(drawable) && GDK_WINDOW_OBJECT(drawable)->destroyed) return; #endif /* MOZ_WIDGET_GTK2 */ if (font->type == GDK_FONT_FONT) { #ifdef MOZ_WIDGET_GTK XFontStruct *xfont = (XFontStruct *) font_private->xfont; #endif /* MOZ_WIDGET_GTK */ #ifdef MOZ_WIDGET_GTK2 XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT(font); #endif /* MOZ_WIDGET_GTK2 */ // gdk does this... we don't need it.. // XSetFont(drawable_private->xdisplay, gc_private->xgc, xfont->fid); // We clamp the sizes down to 32768 which is the maximum width of // a window. Even if a font was 1 pixel high and started at the // left, the maximum size of a draw request could only be 32k. if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0)) { #ifdef MOZ_WIDGET_GTK XDrawString (drawable_private->xdisplay, drawable_private->xwindow, gc_private->xgc, x, y, text, MIN(text_length, 32768)); #endif /* MOZ_WIDGET_GTK */ #ifdef MOZ_WIDGET_GTK2 XDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable), GDK_GC_XGC(gc), x, y, text, MIN(text_length, 32768)); #endif /* MOZ_WIDGET_GTK2 */ } else { #ifdef MOZ_WIDGET_GTK XDrawString16 (drawable_private->xdisplay, drawable_private->xwindow, gc_private->xgc, x, y, (XChar2b *) text, MIN((text_length / 2), 32768)); #endif /* MOZ_WIDGET_GTK */ #ifdef MOZ_WIDGET_GTK2 XDrawString16 (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable), GDK_GC_XGC(gc), x, y, (XChar2b *) text, MIN((text_length / 2), 32768)); #endif /* MOZ_WIDGET_GTK2 */ } } else if (font->type == GDK_FONT_FONTSET) { #ifdef MOZ_WIDGET_GTK XFontSet fontset = (XFontSet) font_private->xfont; XmbDrawString (drawable_private->xdisplay, drawable_private->xwindow, fontset, gc_private->xgc, x, y, text, text_length); #endif /* MOZ_WIDGET_GTK */ #ifdef MOZ_WIDGET_GTK2 XFontSet fontset = (XFontSet) GDK_FONT_XFONT(font); XmbDrawString (GDK_WINDOW_XDISPLAY(drawable), GDK_DRAWABLE_XID(drawable), fontset, GDK_GC_XGC(gc), x, y, text, text_length); #endif /* MOZ_WIDGET_GTK2 */ } else g_error("undefined font type\n"); }