Exemplo n.º 1
0
 public void Dispose()
 {
     foreach (IntPtr font in fonts)
     {
         LibXft.XftFontClose(display, font);
     }
 }
Exemplo n.º 2
0
        private IntPtr GetFontByCodePointNonCached(int codePoint)
        {
            foreach (IntPtr font in fonts)
            {
                if (LibXft.XftCharExists(display, font, (uint)codePoint) != 0)
                {
                    return(font);
                }
            }

            if (fonts.Count >= MaxFontsCount)
            {
                return(MainFont);
            }

            IntPtr fontPtr = LibXft.XftFontOpenName(display, screen, GetXftFontConfig(fontConfig, codePoint));

            if (fontPtr == IntPtr.Zero)
            {
                return(MainFont);
            }

            if (LibXft.XftCharExists(display, fontPtr, (uint)codePoint) == 0)
            {
                LibXft.XftFontClose(display, fontPtr);
                return(MainFont);
            }

            fonts.Add(fontPtr);
            return(fontPtr);
        }
Exemplo n.º 3
0
        public Size MeasureString(FontConfig font, string text)
        {
            XftFontExt fontExt = objectCache.GetXftFont(font);

            byte[] utf32Text = Encoding.UTF32.GetBytes(text);

            int      width           = 0;
            GCHandle utf32TextHandle = GCHandle.Alloc(utf32Text, GCHandleType.Pinned);

            try
            {
                IntPtr utf32TextPtr = utf32TextHandle.AddrOfPinnedObject();
                foreach (var range in fontExt.GetRanges(utf32Text))
                {
                    LibXft.XftTextExtents32(
                        display,
                        range.Font,
                        utf32TextPtr + range.Start,
                        (range.End - range.Start) / 4,
                        out var extents
                        );
                    width += extents.xOff;
                }
            }
            finally
            {
                utf32TextHandle.Free();
            }

            var fontInfo = Marshal.PtrToStructure <XftFont>(fontExt.MainFont);

            return(new Size(width, fontInfo.height));
        }
Exemplo n.º 4
0
 private int DrawStringRange(
     IntPtr xftDraw,
     IntPtr xftColorPtr,
     IntPtr font,
     int x,
     int y,
     IntPtr utf32TextPtr,
     int rangeStart,
     int rangeEnd
     )
 {
     LibXft.XftTextExtents32(
         display,
         font,
         utf32TextPtr + rangeStart,
         (rangeEnd - rangeStart) / 4,
         out var extents
         );
     LibXft.XftDrawString32(
         xftDraw,
         xftColorPtr,
         font,
         x,
         y,
         utf32TextPtr + rangeStart,
         (rangeEnd - rangeStart) / 4
         );
     return(extents.xOff);
 }
Exemplo n.º 5
0
        public void DrawString(Color color, FontConfig font, int x, int y, string text)
        {
            x -= origin.X;
            y -= origin.Y;

            var xftColorPtr = Marshal.AllocHGlobal(Marshal.SizeOf <XftColor>());

            try
            {
                XRenderColor xColor = new XRenderColor(color);
                LibXft.XftColorAllocValue(
                    display,
                    visual,
                    colormap,
                    ref xColor,
                    xftColorPtr
                    );

                try
                {
                    XftFontExt fontExt  = objectCache.GetXftFont(font);
                    var        fontInfo = Marshal.PtrToStructure <XftFont>(fontExt.MainFont);

                    int xOffset = DrawString(xftDraw, xftColorPtr, fontExt, x, y + fontInfo.ascent, text);

                    if (font.IsUnderline)
                    {
                        int lineHeight = Convert.ToInt32(Math.Max(font.Size / 10, 1));
                        LibXRender.XRenderFillRectangle(
                            display, PictOp.PictOpOver, pictureId, ref xColor,
                            x,
                            y + fontInfo.ascent + (fontInfo.descent - lineHeight) / 2,
                            (uint)xOffset,
                            (uint)lineHeight
                            );
                    }

                    if (font.IsStrikeout)
                    {
                        int lineHeight = Convert.ToInt32(Math.Max(font.Size / 20, 1));
                        LibXRender.XRenderFillRectangle
                        (
                            display, PictOp.PictOpOver, pictureId, ref xColor,
                            x,
                            y + fontInfo.ascent - (2 * fontInfo.ascent + 3 * lineHeight) / 6,
                            (uint)xOffset,
                            (uint)lineHeight
                        );
                    }
                }
                finally
                {
                    LibXft.XftColorFree(display, visual, colormap, xftColorPtr);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(xftColorPtr);
            }
        }
Exemplo n.º 6
0
        public void SetClipRectangle(int x, int y, int width, int height)
        {
            x -= origin.X;
            y -= origin.Y;

            clipRectangles = new[] { new XRectangle(x, y, width, height) };
            LibXRender.XRenderSetPictureClipRectangles(display, pictureId, 0, 0, clipRectangles, 1);
            LibXft.XftDrawSetClipRectangles(xftDraw, 0, 0, clipRectangles, 1);
        }
Exemplo n.º 7
0
        public static X11Canvas CreateForDrawable(
            IntPtr display,
            int screenNum,
            X11ObjectCache objectCache,
            IntPtr visual,
            ulong colormap,
            IntPtr pictFormatPtr,
            ulong drawableId
            )
        {
            const XRenderPictureAttributeMask attrMask =
                XRenderPictureAttributeMask.CPPolyEdge |
                XRenderPictureAttributeMask.CPPolyMode;

            XRenderPictureAttributes attr = new XRenderPictureAttributes
            {
                poly_edge = XRenderPolyEdge.Smooth,
                poly_mode = XRenderPolyMode.Imprecise
            };

            ulong pictureId = LibXRender.XRenderCreatePicture
                              (
                display,
                drawableId,
                pictFormatPtr,
                attrMask,
                ref attr
                              );

            IntPtr    xftDraw = IntPtr.Zero;
            X11Canvas canvas  = null;

            try
            {
                xftDraw = LibXft.XftDrawCreate(display, drawableId, visual, colormap);
                canvas  = new X11Canvas(display, screenNum, objectCache, visual, colormap, pictFormatPtr, drawableId, pictureId, xftDraw);
                xftDraw = IntPtr.Zero;
            }
            finally
            {
                if (canvas == null)
                {
                    if (xftDraw != IntPtr.Zero)
                    {
                        LibXft.XftDrawDestroy(xftDraw);
                    }

                    LibXRender.XRenderFreePicture(display, pictureId);
                }
            }

            return(canvas);
        }
Exemplo n.º 8
0
        public static XftFontExt Create(FontConfig fontConfig, IntPtr display, int screen)
        {
            IntPtr fontPtr = LibXft.XftFontOpenName(display, screen, GetXftFontConfig(fontConfig, -1));

            return(new XftFontExt(fontConfig, display, screen, fontPtr));
        }
Exemplo n.º 9
0
 public void Dispose()
 {
     LibXft.XftDrawDestroy(xftDraw);
     LibXRender.XRenderFreePicture(display, pictureId);
 }