Example #1
0
        /// <summary>Returns a list of all monospace fonts installed in the system.</summary>
        public static IEnumerable <string> GetMonospaceFonts()
        {
            if (_monospaceFontNames == null)
            {
                _monospaceFontNames = new HashSet <string>();
                LOGFONT lf       = createLogFont("");
                IntPtr  plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf));
                Marshal.StructureToPtr(lf, plogFont, true);

                int ret = 0;
                try
                {
                    using (var bmp = new Bitmap(1024, 768, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
                        using (var graphics = Graphics.FromImage(bmp))
                        {
                            IntPtr hdc = graphics.GetHdc();
                            ret = EnumFontFamiliesEx(hdc, plogFont, enumFontsCallback, IntPtr.Zero, 0);
                            graphics.ReleaseHdc(hdc);
                        }
                }
                finally
                {
                    Marshal.DestroyStructure(plogFont, typeof(LOGFONT));
                }
            }
            return(_monospaceFontNames);
        }
Example #2
0
        IntPtr CreateFontIndirect_Hook(LOGFONT lplf)
        {
#if DEBUG
            try
            {
                lock (_messageQueue)
                {
                    if (_messageQueue.Count < 1000)
                    {
                        _messageQueue.Enqueue(string.Format($"[{EasyHook.RemoteHooking.GetCurrentProcessId()}:{EasyHook.RemoteHooking.GetCurrentThreadId()}]: CreateFontIndirect_Hook {lplf}"));
                    }
                }
            }
            catch
            {
            }
#endif

            lplf.lfQuality = FontQuality.DEFAULT_QUALITY;
            lplf.lfCharSet = FontCharSet.RUSSIAN_CHARSET;
            if (!OkFonts.Contains(lplf.lfFaceName))
            {
                lplf.lfFaceName = "Arial";
            }
            // now call the original API...
            return(CreateFontIndirectA(lplf));
        }
Example #3
0
        public void ToLogFont_InvokeGraphics_ReturnsExpected(TextRenderingHint textRenderingHint, int expectedQuality)
        {
            using (FontFamily family = FontFamily.GenericMonospace)
                using (var font = new Font(family, 10))
                    using (var image = new Bitmap(10, 10))
                        using (Graphics graphics = Graphics.FromImage(image))
                        {
                            graphics.TextRenderingHint = textRenderingHint;

                            var logFont = new LOGFONT();
                            font.ToLogFont(logFont, graphics);

                            Assert.Equal(-13, logFont.lfHeight);
                            Assert.Equal(0, logFont.lfWidth);
                            Assert.Equal(0, logFont.lfEscapement);
                            Assert.Equal(0, logFont.lfOrientation);
                            Assert.Equal(400, logFont.lfWeight);
                            Assert.Equal(0, logFont.lfItalic);
                            Assert.Equal(0, logFont.lfUnderline);
                            Assert.Equal(0, logFont.lfStrikeOut);
                            Assert.Equal(1, logFont.lfCharSet);
                            Assert.Equal(0, logFont.lfOutPrecision);
                            Assert.Equal(0, logFont.lfClipPrecision);
                            Assert.Equal(0, logFont.lfQuality);
                            Assert.Equal(0, logFont.lfPitchAndFamily);
                            Assert.Equal(family.Name, logFont.lfFaceName);
                        }
        }
Example #4
0
        private void buildList()
        {
            // Need an HDC to pass to EnumFontFamilies
            IntPtr hwnd = GetDesktopWindow();
            IntPtr hdc  = GetDC(hwnd);

            LOGFONT logFont = new LOGFONT();

            enumFontDelegate = new EnumFontDelegate(EnumFontFamiliesExProc);
            fpEnumProc       = Marshal.GetFunctionPointerForDelegate(enumFontDelegate);

            EnumFontFamilies(hdc, null, fpEnumProc, IntPtr.Zero);

            // We got a list of the major families.  Copy the list,
            // then clear it so we can go back and grab all the individual fonts.
            List <string> fontFamilies = new List <string>();

            fontFamilies.AddRange(fontNames);
            fontNames.Clear();

            foreach (string fontFamily in fontFamilies)
            {
                EnumFontFamilies(hdc, fontFamily, fpEnumProc, IntPtr.Zero);
            }

            ReleaseDC(hdc);

            foreach (string s in fontNames)
            {
                //listBox1.Items.Add(s);
            }
        }
 private static void AddCharSet(string fontName)
 {
     if (fontName != null)
     {
         lock (StyleProperties.m_charSetLookupLock)
         {
             if (!StyleProperties.m_charSetLookup.ContainsKey(fontName))
             {
                 Font font = null;
                 try
                 {
                     bool flag  = false;
                     bool flag2 = false;
                     font = FontCache.CreateGdiPlusFont(fontName, 400f, ref flag, ref flag2, false, false);
                     LOGFONT lOGFONT = new LOGFONT();
                     font.ToLogFont(lOGFONT);
                     StyleProperties.m_charSetLookup.Add(fontName, (CharSet)lOGFONT.lfCharSet);
                 }
                 finally
                 {
                     if (font != null)
                     {
                         font.Dispose();
                         font = null;
                     }
                 }
             }
         }
     }
 }
    public static void Main()
    {
        LOGFONT lf = new LOGFONT();
        lf.lfHeight = 9;
        lf.lfFaceName = "Arial";
        IntPtr handle = CreateFontIndirect(lf);

        if (IntPtr.Zero == handle)
        {
            Console.WriteLine("Can't creates a logical font.");
        }
        else
        {

            if (IntPtr.Size == 4)
                Console.WriteLine("{0:X}", handle.ToInt32());
            else
                Console.WriteLine("{0:X}", handle.ToInt64());

            // delete the logical font created.
            if (!DeleteObject(handle))
                Console.WriteLine("Can't delete the logical font");

        }
    }
Example #7
0
    public static void Main()
    {
        LOGFONT lf = new LOGFONT();

        lf.lfHeight   = 9;
        lf.lfFaceName = "Arial";
        IntPtr handle = CreateFontIndirect(lf);

        if (IntPtr.Zero == handle)
        {
            Console.WriteLine("Can't creates a logical font.");
        }
        else
        {
            if (IntPtr.Size == 4)
            {
                Console.WriteLine("{0:X}", handle.ToInt32());
            }
            else
            {
                Console.WriteLine("{0:X}", handle.ToInt64());
            }

            // delete the logical font created.
            if (!DeleteObject(handle))
            {
                Console.WriteLine("Can't delete the logical font");
            }
        }
    }
        public LOGFONT GetThemeFont(int partId, int stateId, int propertyId)
        {
            var     value = new LOGFONT();
            HResult hr    = StyleNativeMethods.GetThemeFont(theme, IntPtr.Zero, partId, stateId, propertyId, value);

            return(Found(hr) ? value : null);
        }
Example #9
0
        protected override void OnLoad(EventArgs e)
        {
            //build list of OpenType fonts
            LOGFONT lf = new LOGFONT();

            IntPtr plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf));
            Marshal.StructureToPtr(lf, plogFont, true);

            try
            {
                fontList.Clear();
                using (Graphics G = CreateGraphics())
                {
                    IntPtr P = G.GetHdc();
                    EnumFontFamiliesEx(P, plogFont, Callback, IntPtr.Zero, 0);
                    G.ReleaseHdc(P);
                }
            }
            finally
            {
                Marshal.DestroyStructure(plogFont, typeof(LOGFONT));
            }

            //sort fonts
            fontList.Sort((f1, f2) => f1.elfFullName.CompareTo(f2.elfFullName));
            //build combobox
            cbFont.Items.Clear();
            foreach (var item in fontList)
                cbFont.Items.Add(item);
        }
Example #10
0
        /// <summary>
        /// Sets the font attributes to be used for text within the preview handler.
        /// </summary>
        /// <param name="plf">A pointer to a LOGFONTW Structure containing the necessary attributes for the font to use.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IPreviewHandlerVisuals.SetFont(ref LOGFONT plf)
        {
            //  Log key events.
            Log("IPreviewHandlerVisuals.SetFont called.");

            //  Call the virtual function.
            try
            {
                LOGFONT logfont = plf;
                OnPreviewHostThread(
                    () =>
                {
                    //  Call the abstract function.
                    if (previewHandlerControl != null)
                    {
                        previewHandlerControl.SetVisualsFont(Font.FromLogFont(logfont));
                    }
                });
            }
            catch (Exception exception)
            {
                //  Log the error.
                LogError("An exception occured when setting the font.", exception);
                throw;
            }

            //  Return success.
            return(WinError.S_OK);
        }
Example #11
0
        private static LOGFONT CreatePointFontStruct(string fontName, int pointSize, bool bold, bool italic)
        {
            const byte DEFAULT_CHARSET = 1;
            const long FW_BOLD         = 700;
            const int  LOGPIXELSY      = 90;

            LOGFONT font = new LOGFONT();

            font.lfCharSet  = DEFAULT_CHARSET;
            font.lfFaceName = fontName;
            if (bold)
            {
                font.lfWeight = FW_BOLD;
            }
            if (italic)
            {
                font.lfItalic = 1;
            }

            using (GraphicsContext context = GraphicsContext.CreateOffscreenContext())
            {
                font.lfHeight = -NativeMethods.MulDiv(pointSize, context.GetCapability(LOGPIXELSY), 72);
            }

            return(font);
        }
Example #12
0
 private void cboFonts_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         if (!m_Loaded || cboFonts.SelectedIndex < 0)
         {
             return;
         }
         var lf   = (LOGFONT)e.AddedItems[0];
         var logF = new LOGFONT();
         logF.Init();
         logF.SetFontFace(lf.lfFaceName);
         logF.SetFontSize((int)cboFontSize.SelectedItem);
         m_Group.Font = logF;
         PNStatic.DrawSkinlessPreview(m_Group, brdFrame, blkCaption, brdBody, blkBody);
         if (lstSkins.SelectedIndex >= 0)
         {
             PNStatic.DrawSkinPreview(m_Group, m_Group.Skin, imgSkin);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Example #13
0
 public HCFont()
 {
     FFontStyles    = new HCFontStyles();
     FPixelsPerInch = HCCanvas.ScreenLogPixels;
     FLogFont       = new LOGFONT();
     ReCreateHandle();
 }
 private static void AddCharSet(string fontName)
 {
     if (fontName == null)
     {
         return;
     }
     lock (m_charSetLookupLock)
     {
         if (m_charSetLookup.ContainsKey(fontName))
         {
             return;
         }
         Font font = null;
         try
         {
             bool bold   = false;
             bool italic = false;
             font = FontCache.CreateGdiPlusFont(fontName, 400f, ref bold, ref italic, lineThrough: false, underLine: false);
             LOGFONT lOGFONT = new LOGFONT();
             font.ToLogFont(lOGFONT);
             m_charSetLookup.Add(fontName, (CharSet)lOGFONT.lfCharSet);
         }
         finally
         {
             if (font != null)
             {
                 font.Dispose();
                 font = null;
             }
         }
     }
 }
Example #15
0
        public static List <FontData> Invoke(Func <FontData, bool> filter = null)
        {
            EnumFontFamiliesEx container = new EnumFontFamiliesEx
            {
                _filter = filter
            };

            Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);

            try
            {
                IntPtr  hdc     = graphics.GetHdc();
                LOGFONT logfont = new LOGFONT
                {
                    lfCharSet = (byte)FontLanguageCharSet.DEFAULT_CHARSET
                };
                EnumFontFamiliesEx(hdc, ref logfont, new FONTENUMPROC(container.EnumFontFamiliesExCallback), IntPtr.Zero, 0);
            }
            catch (Exception)
            {
            }
            finally
            {
                graphics.ReleaseHdc();
            }

            return(container._fontDatas);
        }
        public LOGFONT GetThemeSysFont(int propertyId)
        {
            var     value = new LOGFONT();
            HResult hr    = StyleNativeMethods.GetThemeSysFont(theme, propertyId, value);

            return(Found(hr) ? value : null);
        }
Example #17
0
 public static string GetFontFaceName(string fn)
 {
     Font ft = new Font(fn, 9F);
     LOGFONT lt = new LOGFONT();
     ft.ToLogFont(lt);
     return lt.lfFaceName;
 }
Example #18
0
        protected TCustomForm()
        {
            messageTable = new Dictionary <int, MessageProc>()
            {
                { TApplication.CM_ACTIONEXECUTE, CMActionExecute },
                { TApplication.CM_ACTIONUPDATE, CMActionUpdate }
            };

            //http://stackoverflow.com/questions/4347873/changing-font-smoothing-for-my-application-alone-and-not-the-global-windows-font
            LOGFONT lfont      = new LOGFONT();
            object  boxedLFont = lfont;

            this.Font.ToLogFont(boxedLFont);
            lfont           = (LOGFONT)boxedLFont;
            lfont.lfCharSet = LOGFONT.DEFAULT_CHARSET;
            lfont.lfQuality = LOGFONT.NONANTIALIASED_QUALITY;
            this.Font       = Font.FromLogFont(lfont);
            if (TApplication.Instance.AppInitialized && TApplication.Instance.Icon != null)
            {
                Icon = TApplication.Instance.Icon;
            }

            //TODO: inject a call to AfterConstruction() in the calling frame!
            // Use factory pattern Create<TForm>() as long as the injection is not implemented.
        }
Example #19
0
        public void GetFonts()
        {
            LOGFONT lf = CreateLogFont("");

            IntPtr plogFont = Marshal.AllocHGlobal(Marshal.SizeOf(lf));

            Marshal.StructureToPtr(lf, plogFont, true);

            int ret = 0;

            try
            {
                //If anyone knows of a better way to get the pointer please let me know
                var pictureBox = new PictureBox();
                var graphic    = pictureBox.CreateGraphics();
                var ptr        = graphic.GetHdc();

                del1 = new EnumFontExDelegate(callback1);
                ret  = EnumFontFamiliesEx(ptr, plogFont, del1, IntPtr.Zero, 0);

                graphic.ReleaseHdc(ptr);
            }
            catch
            {
                Console.WriteLine("Error!");
            }
            finally
            {
                Marshal.DestroyStructure(plogFont, typeof(LOGFONT));
            }
        }
Example #20
0
        private void SetIMEWindowFont(Font f)
        {
            if (disableIME || hIMEWnd == IntPtr.Zero)
            {
                return;
            }

            if (lf == null)
            {
                lf = new LOGFONT();
                try
                {
                    f.ToLogFont(lf);
                }
                catch (Exception ex)
                {
                    //todo
                }
                lf.lfFaceName = f.Name;  // This is very important! "Font.ToLogFont" Method sets invalid value to LOGFONT.lfFaceName
            }

            try
            {
                SendMessage(
                    hIMEWnd,
                    WM_IME_CONTROL,
                    new IntPtr(IMC_SETCOMPOSITIONFONT),
                    lf
                    );
            }
            catch (AccessViolationException ex)
            {
                Handle(ex);
            }
        }
Example #21
0
        public void ToLogFont_AssertUnmanagedCode()
        {
            Font    f  = new Font("Arial", 10);
            LOGFONT lf = new LOGFONT();

            f.ToLogFont(lf);
            Assert.AreEqual(400, lf.lfWeight, "lfWeight");
            Assert.AreEqual(1, lf.lfCharSet, "lfCharSet");
            Assert.AreEqual(f.Name, lf.lfFaceName, "lfFaceName");

            LOGFONT_STRUCT lfs = new LOGFONT_STRUCT();

            f.ToLogFont(lfs);
            Assert.AreEqual(0, lfs.lfWeight, "struct-lfWeight");
            Assert.AreEqual(0, lfs.lfCharSet, "struct-lfCharSet");
            Assert.AreEqual(0, lfs.lfHeight, "struct-lfHeight");
            Assert.AreEqual(0, lfs.lfWidth, "struct-lfWidth");
            Assert.AreEqual(0, lfs.lfEscapement, "struct-lfEscapement");
            Assert.AreEqual(0, lfs.lfOrientation, "struct-lfOrientation");
            Assert.AreEqual(0, lfs.lfWeight, "struct-lfWeight");
            Assert.AreEqual(0, lfs.lfItalic, "struct-lfItalic");
            Assert.AreEqual(0, lfs.lfUnderline, "struct-lfUnderline");
            Assert.AreEqual(0, lfs.lfStrikeOut, "struct-lfStrikeOut");
            Assert.AreEqual(0, lfs.lfCharSet, "struct-lfCharSet");
            Assert.AreEqual(0, lfs.lfOutPrecision, "struct-lfOutPrecision");
            Assert.AreEqual(0, lfs.lfClipPrecision, "struct-lfClipPrecision");
            Assert.AreEqual(0, lfs.lfQuality, "struct-lfQuality");
            Assert.AreEqual(0, lfs.lfPitchAndFamily, "struct-lfPitchAndFamily");
            Assert.IsNull(lfs.lfFaceName, "struct-lfFaceName");
        }
Example #22
0
        public void FromLogFont_ValidLogFont_ReturnsExpected(FontStyle fontStyle, int weight, byte charSet)
        {
            // The boundary values of the weight that is considered Bold are different between Windows 7 and Windows 8.
            if (PlatformDetection.IsWindows7 || PlatformDetection.IsWindows8x)
            {
                return;
            }

            using (FontFamily family = FontFamily.GenericMonospace)
            {
                var logFont = new LOGFONT
                {
                    lfFaceName  = family.Name,
                    lfWeight    = weight,
                    lfItalic    = (fontStyle & FontStyle.Italic) != 0 ? (byte)1 : (byte)0,
                    lfStrikeOut = (fontStyle & FontStyle.Strikeout) != 0 ? (byte)1 : (byte)0,
                    lfUnderline = (fontStyle & FontStyle.Underline) != 0 ? (byte)1 : (byte)0,
                    lfCharSet   = charSet
                };
                using (Font font = Font.FromLogFont(logFont))
                {
                    VerifyFont(font, family.Name, font.Size, fontStyle, GraphicsUnit.World, charSet, expectedGdiVerticalFont: false);
                }
            }
        }
Example #23
0
        public override IText AddText(string text, double fontSize, System.Windows.Media.SolidColorBrush brush)
        {
            if (cachedTypeface == null)
            {
                cachedTypeface = CreateTypeface();
            }

            LOGFONT logfont = new LOGFONT();

            logfont.lfFaceName = cachedTypeface.FontFamily.Source;
            logfont.lfHeight   = -(int)fontSize;
            //logfont.lfOutPrecision = 4;
            //logfont.lfQuality = 5;

            MyText myText = new MyText {
                parent = this,
                text   = text,
                color  = brush.Color.R | (brush.Color.G << 8) | (brush.Color.B << 16),
                font   = CreateFontIndirect(ref logfont)
            };

            //myText.brush = new SolidBrush(myText.color);

            texts.Add(myText);
            return(myText);
        }
Example #24
0
        private static bool CheckFamily(LOGFONT lf, FontFamilies families)
        {
            FontPitchAndFamily v = (FontPitchAndFamily)(lf.lfPitchAndFamily >> 2 << 2);

            switch (v)
            {
            case FontPitchAndFamily.FF_DECORATIVE:
            {
                if ((families & FontFamilies.Decorative) == 0)
                {
                    return(false);
                }
                break;
            }

            case FontPitchAndFamily.FF_DONTCARE:
            {
                return(families == FontFamilies.DontCare ? true : false);
            }

            case FontPitchAndFamily.FF_MODERN:
            {
                if ((families & FontFamilies.Modern) == 0)
                {
                    return(false);
                }
                break;
            }

            case FontPitchAndFamily.FF_ROMAN:
            {
                if ((families & FontFamilies.Roman) == 0)
                {
                    return(false);
                }
                break;
            }

            case FontPitchAndFamily.FF_SWISS:
            {
                if ((families & FontFamilies.Swiss) == 0)
                {
                    return(false);
                }
                break;
            }

            case FontPitchAndFamily.FF_SCRIPT:
            {
                if ((families & FontFamilies.Script) == 0)
                {
                    return(false);
                }
                break;
            }
            }

            return(true);
        }
Example #25
0
 /// <summary>
 /// コンストラクタ。
 /// </summary>
 /// <param name="dummy">ダミーパラメータ。何を渡してもOK。</param>
 public ICONMETRICS(int dummy)
 {
     this.cbSize       = 0;
     this.iHorzSpacing = 0;
     this.iVertSpacing = 0;
     this.iTitleWrap   = 0;
     this.lfFont       = new LOGFONT();
 }
Example #26
0
        public static int CalOffsetY(Font f)
        {
            LOGFONT lg = new LOGFONT();

            f.ToLogFont(lg);
            Log.Debug($"Name:{f.Name} Font.Height: {f.Height} lfHeight: {lg.lfHeight}");
            return(f.Height - Math.Abs(lg.lfHeight));
        }
Example #27
0
        public void Dispose_ToLogFont()
        {
#if !TARGET_JVM
            Font f = new Font(name, 12.5f);
            f.Dispose();
            LOGFONT lf = new LOGFONT();
            f.ToLogFont(lf);
#endif
        }
Example #28
0
        public static bool IsSymbolFont([NotNull] Font font)
        {
            const byte SYMBOL_FONT = 2;

            LOGFONT logicalFont = new LOGFONT();

            font.ToLogFont(logicalFont);
            return(logicalFont.lfCharSet == SYMBOL_FONT);
        }
Example #29
0
        public void Dispose_ToLogFont()
        {
            Font f = new Font(name, 12.5f);

            f.Dispose();
            LOGFONT lf = new LOGFONT();

            Assert.Throws <ArgumentException> (() => f.ToLogFont(lf));
        }
Example #30
0
        /// <summary>
        ///
        /// </summary>
        public SafeLogFont(string faceName)
        {
            var logfont = new LOGFONT()
            {
                lfFaceName = faceName,
            };

            _logFont = CreateFontIndirect(ref logfont);
        }
Example #31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="typeface"></param>
        /// <param name="size"></param>
        public SafeLogFont(Typeface typeface, int size)
        {
            var logfont = new LOGFONT()
            {
                lfFaceName       = typeface.FontFamily.Source,
                lfHeight         = -(int)(typeface.FontFamily.LineSpacing * 3 / 4 * size),
                lfPitchAndFamily = FontPitchAndFamily.FIXED_PITCH,
                lfCharSet        = FontCharSet.ANSI_CHARSET,
            };

            if (typeface.Weight == FontWeights.Thin)
            {
                logfont.lfWeight = FontWeight.FW_THIN;
            }
            else if (typeface.Weight == FontWeights.ExtraLight || typeface.Weight == FontWeights.UltraLight)
            {
                logfont.lfWeight = FontWeight.FW_EXTRALIGHT;
            }
            else if (typeface.Weight == FontWeights.Light)
            {
                logfont.lfWeight = FontWeight.FW_LIGHT;
            }
            else if (typeface.Weight == FontWeights.Normal || typeface.Weight == FontWeights.Regular)
            {
                logfont.lfWeight = FontWeight.FW_NORMAL;
            }
            else if (typeface.Weight == FontWeights.Medium)
            {
                logfont.lfWeight = FontWeight.FW_MEDIUM;
            }
            else if (typeface.Weight == FontWeights.SemiBold || typeface.Weight == FontWeights.DemiBold)
            {
                logfont.lfWeight = FontWeight.FW_SEMIBOLD;
            }
            else if (typeface.Weight == FontWeights.Bold)
            {
                logfont.lfWeight = FontWeight.FW_BOLD;
            }
            else if (typeface.Weight == FontWeights.ExtraBold || typeface.Weight == FontWeights.UltraBold)
            {
                logfont.lfWeight = FontWeight.FW_EXTRABOLD;
            }
            else if (typeface.Weight == FontWeights.Black || typeface.Weight == FontWeights.ExtraBlack ||
                     typeface.Weight == FontWeights.UltraBlack || typeface.Weight == FontWeights.Heavy)
            {
                logfont.lfWeight = FontWeight.FW_HEAVY;
            }

            if (typeface.Style == FontStyles.Italic)
            {
                logfont.lfItalic = true;
            }

            //TODO: Реализовать подчеркивание и зачеркивание

            _logFont = CreateFontIndirect(ref logfont);
        }
Example #32
0
        public void Dispose_ToLogFont()
        {
            Font f = new Font(name, 12.5f);

            f.Dispose();
            LOGFONT lf = new LOGFONT();

            f.ToLogFont(lf);
        }
Example #33
0
        private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if ((e.State & DrawItemState.Disabled) > 0)
            {
                return;
            }

            Graphics g = e.Graphics;

            e.DrawBackground();

            if ((e.State & DrawItemState.ComboBoxEdit) > 0)
            {
                e.DrawBackground();
                TextRenderer.DrawText(g, FFontName, e.Font, new Point(e.Bounds.X, e.Bounds.Y), e.ForeColor);
            }
            else if (e.Index >= 0)
            {
                string name = (string)Items[e.Index];
                if (!FExistingFonts.Contains(name))
                {
                    return;
                }

                using (FontFamily family = new FontFamily(name))
                    using (Font font = new Font(name, 14, GetFirstAvailableFontStyle(family)))
                    {
                        g.DrawImage(Res.GetImage(59), e.Bounds.X + 2, e.Bounds.Y + 2);

                        LOGFONT lf = new LOGFONT();
                        font.ToLogFont(lf);
                        SizeF sz;

                        if (lf.lfCharSet == 2)
                        {
                            sz = g.MeasureString(name, e.Font);
                            int w = (int)sz.Width;
                            TextRenderer.DrawText(g, name, e.Font, new Point(e.Bounds.X + 20, e.Bounds.Y + (e.Bounds.Height - (int)sz.Height) / 2), e.ForeColor);
                            sz = g.MeasureString(name, font);
                            TextRenderer.DrawText(g, name, font, new Point(e.Bounds.X + w + 28, e.Bounds.Y + (e.Bounds.Height - (int)sz.Height) / 2), e.ForeColor);
                        }
                        else
                        {
                            sz = g.MeasureString(name, font);
                            TextRenderer.DrawText(g, name, font, new Point(e.Bounds.X + 20, e.Bounds.Y + (e.Bounds.Height - (int)sz.Height) / 2), e.ForeColor);
                        }


                        if (e.Index == FMruFonts.Count - 1)
                        {
                            g.DrawLine(Pens.Gray, e.Bounds.Left, e.Bounds.Bottom - 3, e.Bounds.Right, e.Bounds.Bottom - 3);
                            g.DrawLine(Pens.Gray, e.Bounds.Left, e.Bounds.Bottom - 1, e.Bounds.Right, e.Bounds.Bottom - 1);
                        }
                    }
            }
        }
        public bool GdiMeasureString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Point ptDraw,
            ref float pfPixelsStartX,
            ref float pfPixelsStartY,
            ref float pfDestWidth,
            ref float pfDestHeight)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    ptDraw);

                if (false == b)
                {
                    return false;
                }

                pfDestWidth = ptDraw.X;
                pfDestHeight = ptDraw.Y;
                b = GDIPath.MeasureGraphicsPath(pGraphics, pPath, ref pfPixelsStartX, ref pfPixelsStartY, ref pfDestWidth, ref pfDestHeight);

                if (false == b)
                {
                    return false;
                }

                float pixelThick = 0.0f;
                float fStartX = 0.0f;
                float fStartY = 0.0f;
                float fDestHeight = 0.0f;
                b = GDIPath.ConvertToPixels(pGraphics, m_nThickness, 0.0f, ref fStartX, ref fStartY, ref pixelThick, ref fDestHeight);

                if (false == b)
                {
                    return false;
                }

                pfDestWidth += pixelThick;
                pfDestHeight += pixelThick;
            }

            return true;
        }
Example #35
0
        public static Font ToClearType(this Font font)
        {
            var lf = new LOGFONT();

            var hFont = font.ToHfont();
            if (NativeMethods.GetObject(hFont, Marshal.SizeOf(lf), ref lf) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            NativeMethods.DeleteObject(hFont);

            lf.Quality = 6; // CLEARTYPE_COMPAT_QUALITY

            hFont = NativeMethods.CreateFontIndirect(ref lf);

            return Font.FromHfont(hFont);
        }
    public bool LoadSubtitles(IGraphBuilder graphBuilder, string filename)
    {
      FreeSubtitles();
      LoadSettings();

      {
        //remove InternalScriptRenderer as it takes subtitle pin
        IBaseFilter isr = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.InternalScriptRenderer, out isr);
        if (isr != null)
        {
          graphBuilder.RemoveFilter(isr);
          DirectShowUtil.ReleaseComObject(isr);
        }
      }

      vobSub = (IDirectVobSub)DirectVobSubUtil.AddToGraph(graphBuilder);
      if (vobSub == null)
        return false;

      {
        //set style
        Log.Debug("VideoPlayerVMR9: Setting DirectVobsub parameters");
        LOGFONT logFont = new LOGFONT();
        int txtcolor;
        bool fShadow, fOutLine, fAdvancedRenderer = false;
        int size = Marshal.SizeOf(typeof(LOGFONT));
        vobSub.get_TextSettings(logFont, size, out txtcolor, out fShadow, out fOutLine, out fAdvancedRenderer);
        FontStyle fontStyle = defStyle.fontIsBold ? FontStyle.Regular : FontStyle.Bold;
        Font Subfont = new Font(defStyle.fontName, defStyle.fontSize, fontStyle, GraphicsUnit.Point,
                                (byte)defStyle.fontCharset);
        Subfont.ToLogFont(logFont);
        fShadow = defStyle.shadow > 0;
        fOutLine = defStyle.isBorderOutline;
        vobSub.put_TextSettings(logFont, size, defStyle.fontColor, fShadow, fOutLine, fAdvancedRenderer);
        vobSub.put_FileName(filename);

        bool fBuffer, fOnlyForced, fPolygonize;
        vobSub.get_VobSubSettings(out fBuffer, out fOnlyForced, out fPolygonize);
        vobSub.put_VobSubSettings(fBuffer, !this.autoShow, fPolygonize);
      }

      {
        //load sub streams
        IBaseFilter hms = null;
        DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.HaaliGuid, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilterSource, out hms);
        if (hms == null)
          DirectShowUtil.FindFilterByClassID(graphBuilder, ClassId.LAVFilter, out hms);
        embeddedSelector = hms as IAMStreamSelect;
        if (embeddedSelector != null)
        {
          AddStreams(embeddedSelector);
        }

        vobSub.get_LanguageCount(out extCount);
        if (intSubs.Count > 0)
        {
          //if there are embedded subtitles,
          //last stream of directvobsub is currently selected embedded subtitle
          extCount--;
        }
      }

      FFDShowEngine.DisableFFDShowSubtitles(graphBuilder);

      Current = 0;
      if (selectionOff)
      {
        Enable = false;
      }
      else
      {
        Enable = autoShow;
      }
      return true;
    }
Example #37
0
 public static string GetFontFaceName(Font ft)
 {
     LOGFONT lt = new LOGFONT();
     ft.ToLogFont(lt);
     return lt.lfFaceName;
 }
Example #38
0
 private void cboFontSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         if (!_Loaded || cboFontSize.SelectedIndex < 0) return;
         var gr = selectedGroup();
         if (gr == null) return;
         var logF = new LOGFONT();
         logF.Init();
         logF.SetFontFace(gr.Font.lfFaceName);
         logF.SetFontSize((int)cboFontSize.SelectedItem);
         gr.Font = logF;
         PNStatic.DrawSkinlessPreview(gr, brdFrame, blkCaption, brdBody, blkBody);
         if (lstSkins.SelectedIndex >= 0)
         {
             PNStatic.DrawSkinPreview(gr, gr.Skin, imgSkin);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Example #39
0
 void IPreviewHandlerVisuals.SetFont(ref LOGFONT plf)
 {
     Font f = Font.FromLogFont(plf);
     InvokeOnPreviewThread(delegate() { _previewControl.Font = f; });
 }
Example #40
0
 public static extern int GetThemeSysFont(IntPtr hTheme, int iIntID, out LOGFONT pFont);
Example #41
0
 internal static extern int GetObject(IntPtr hObj, int cb, ref LOGFONT objdata);
	public LOGFONT(LOGFONT lf) {}
 public LOGFONT( LOGFONT lf )
 {
     Debug.Assert( lf != null, "lf is null" );
     
     this.lfHeight           = lf.lfHeight;
     this.lfWidth            = lf.lfWidth;
     this.lfEscapement       = lf.lfEscapement;
     this.lfOrientation      = lf.lfOrientation;
     this.lfWeight           = lf.lfWeight;
     this.lfItalic           = lf.lfItalic;
     this.lfUnderline        = lf.lfUnderline;
     this.lfStrikeOut        = lf.lfStrikeOut;
     this.lfCharSet          = lf.lfCharSet;
     this.lfOutPrecision     = lf.lfOutPrecision;
     this.lfClipPrecision    = lf.lfClipPrecision;
     this.lfQuality          = lf.lfQuality;
     this.lfPitchAndFamily   = lf.lfPitchAndFamily;
     this.lfFaceName         = lf.lfFaceName;
 }
Example #44
0
        public override bool GdiDrawString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Point ptDraw)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    ptDraw);

                if (false == b)
                {
                    return false;
                }

                for (int i = 1; i <= m_nThickness; ++i)
                {
                    using (Pen pen = new Pen(m_clrOutline, i))
                    {
                        pen.LineJoin = LineJoin.Round;
                        pGraphics.DrawPath(pen, pPath);
                    }
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        pGraphics.FillPath(brush, pPath);
                    }
                }
                else
                {
                    pGraphics.FillPath(m_brushText, pPath);
                }
            }
            return true;
        }
Example #45
0
 public static extern IntPtr CreateFontIndirect(ref LOGFONT lplf);
    public virtual void ReceiveData(BufferChunk aRecord)
    {
        // First read out the record type
        int recordType = aRecord.NextInt32();

        // Then deserialize the rest from there
        switch (recordType)
        {
            case GDI32.EMR_HEADER:
                break;

            // Transform related
            case GDI32.EMR_SCALEVIEWPORTEXTEX:
            case GDI32.EMR_SCALEWINDOWEXTEX:
                break;

            case GDI32.EMR_SETWINDOWEXTEX:
                {
                    int width = aRecord.NextInt32();
                    int height = aRecord.NextInt32();

                    SetWindowExtent(width, height);
                }
                break;

            case GDI32.EMR_SETWINDOWORGEX:
                {
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();

                    SetWindowOrigin(x, y);
                }
                break;

            case GDI32.EMR_SETVIEWPORTEXTEX:
                {
                    int width = aRecord.NextInt32();
                    int height = aRecord.NextInt32();

                    SetViewportExtent(width, height);
                }
                break;

            case GDI32.EMR_SETVIEWPORTORGEX:
                {
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();
                    
                    SetViewportOrigin(x, y);
                }
                break;

            case GDI32.EMR_SETWORLDTRANSFORM:
            case GDI32.EMR_MODIFYWORLDTRANSFORM:
                break;

            case GDI32.EMR_SETBRUSHORGEX:
                break;

            case GDI32.EMR_EOF:
                Flush();
                break;

            case GDI32.EMR_SETPIXELV:
                {
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();
                    UInt32 colorref = aRecord.NextUInt32();

                    SetPixel(x, y, colorref);
                }
                break;

            case GDI32.EMR_SETMAPPERFLAGS:
                break;

            case GDI32.EMR_SETPOLYFILLMODE:
                SetPolyFillMode(aRecord.NextInt32());
                break;

            case GDI32.EMR_SETSTRETCHBLTMODE:
                break;

            case GDI32.EMR_SETMAPMODE:
                MappingModes aMode = (MappingModes)aRecord.NextInt32();
                SetMappingMode(aMode);
                break;


            case GDI32.EMR_SETTEXTCOLOR:
                SetTextColor(aRecord.NextUInt32());
                break;

            case GDI32.EMR_SETBKCOLOR:
                SetBkColor(aRecord.NextUInt32());
                break;

            case GDI32.EMR_SETDCBRUSHCOLOR:
                SetDefaultBrushColor(aRecord.NextUInt32());
                break;

            case GDI32.EMR_SETDCPENCOLOR:
                SetDefaultPenColor(aRecord.NextUInt32());
                break;

            case GDI32.EMR_SETBKMODE:
                SetBkMode(aRecord.NextInt32());
                break;

            case GDI32.EMR_SETROP2:
                SetROP2((BinaryRasterOps)aRecord.NextInt32());
                break;

            case GDI32.EMR_SETTEXTALIGN:
            case GDI32.EMR_SETCOLORADJUSTMENT:
                break;

            case GDI32.EMR_MOVETOEX:
                MoveTo(aRecord.NextInt32(), aRecord.NextInt32());
                break;

            case GDI32.EMR_OFFSETCLIPRGN:
            case GDI32.EMR_SETMETARGN:
            case GDI32.EMR_EXCLUDECLIPRECT:
            case GDI32.EMR_INTERSECTCLIPRECT:
                break;

            case GDI32.EMR_SAVEDC:
                SaveState();
                break;

            case GDI32.EMR_RESTOREDC:
                RestoreState(aRecord.NextInt32());
                break;

                // Creates a generic pen of any style
            case GDI32.EMR_CREATEPEN:
                {
                    int aStyle = aRecord.NextInt32();
                    int width = aRecord.NextInt32();
                    uint colorref = aRecord.NextUInt32();
                    Guid uniqueID = this.UnpackGuid(aRecord);
                    CreateCosmeticPen((PenStyle)aStyle, colorref, uniqueID);
                }
                break;

            case GDI32.EMR_CREATECOSMETICPEN:
                {
                    int aStyle = aRecord.NextInt32();
                    int width = aRecord.NextInt32();
                    uint colorref = aRecord.NextUInt32();
                    Guid uniqueID = this.UnpackGuid(aRecord);
                    CreateCosmeticPen((PenStyle)aStyle, colorref, uniqueID);
                }
                break;


            case GDI32.EMR_CREATEBRUSHINDIRECT:
                {
                    int aStyle = aRecord.NextInt32();   // chunk += aStyle;
                    int hatch = aRecord.NextInt32(); // chunk += hatch;
                    uint color = aRecord.NextUInt32(); // chunk += color;

                    Guid uniqueID = this.UnpackGuid(aRecord);
                    CreateBrush(aStyle, hatch, color, uniqueID);
                }
                break;

            case GDI32.EMR_SELECTOBJECT:
                break;

            case GDI32.EMR_DELETEOBJECT:
                break;

            case GDI32.EMR_SELECTSTOCKOBJECT:
                SelectStockObject(aRecord.NextInt32());
                break;

            case GDI32.EMR_SELECTUNIQUEOBJECT:
                {
                    Guid uniqueID = this.UnpackGuid(aRecord);
                    SelectUniqueObject(uniqueID);
                }
                break;

            case GDI32.EMR_ELLIPSE:
                {
                    int left = aRecord.NextInt32();
                    int top = aRecord.NextInt32();
                    int right = aRecord.NextInt32();
                    int bottom = aRecord.NextInt32();

                    Ellipse(left, top, right, bottom);
                }
                break;

            case GDI32.EMR_ROUNDRECT:
                {
                    int left = aRecord.NextInt32();
                    int top = aRecord.NextInt32();
                    int right = aRecord.NextInt32();
                    int bottom = aRecord.NextInt32();
                    int width = aRecord.NextInt32();
                    int height = aRecord.NextInt32();

                    RoundRect(left, top, right, bottom, width, height);
                }
                break;

            case GDI32.EMR_RECTANGLE:
                {
                    int left = aRecord.NextInt32();
                    int top = aRecord.NextInt32();
                    int right = aRecord.NextInt32();
                    int bottom = aRecord.NextInt32();

                    Rectangle(left, top, right, bottom);
                }
                break;

            case GDI32.EMR_GRADIENTFILL:    // Only rectangles at the moment
                {
                    // Unpack the vertices
                    TRIVERTEX[] pVertex = this.UnpackTRIVERTEX(aRecord);

                    // unpack the gradient mesh
                    GRADIENT_RECT[] pMesh = UnpackGRADIENT_RECT(aRecord);

                    // pack the mode
                    uint dwMode = aRecord.NextUInt32();

                    this.GradientRectangle(pVertex, pMesh, dwMode);
                }
                break;

            case GDI32.EMR_ARC:
            case GDI32.EMR_ARCTO:
            case GDI32.EMR_ANGLEARC:
            case GDI32.EMR_CHORD:
            case GDI32.EMR_PIE:
                break;

            case GDI32.EMR_SELECTPALETTE:
            case GDI32.EMR_CREATEPALETTE:
            case GDI32.EMR_SETPALETTEENTRIES:
            case GDI32.EMR_RESIZEPALETTE:
            case GDI32.EMR_REALIZEPALETTE:
                break;

            case GDI32.EMR_LINETO:
                LineTo(aRecord.NextInt32(), aRecord.NextInt32());
                break;

            case GDI32.EMR_EXTFLOODFILL:
                break;

            case GDI32.EMR_POLYDRAW:
                //EMRPOLYDRAW polydraw = (EMRPOLYDRAW)aRecord;
                //fRenderer.PolyDraw(polydraw.aptl, polydraw.abTypes);
                break;

            case GDI32.EMR_SETARCDIRECTION:
            case GDI32.EMR_SETMITERLIMIT:
                break;

            case GDI32.EMR_BEGINPATH:
                BeginPath();
                break;

            case GDI32.EMR_ENDPATH:
                EndPath();
                break;

            case GDI32.EMR_FILLPATH:
                FillPath();
                break;

            case GDI32.EMR_STROKEANDFILLPATH:
                DrawPath();
                break;

            case GDI32.EMR_STROKEPATH:
                FramePath();
                break;

            case GDI32.EMR_ABORTPATH:
            case GDI32.EMR_FLATTENPATH:
            case GDI32.EMR_WIDENPATH:
                break;

            case GDI32.EMR_CLOSEFIGURE:

            case GDI32.EMR_SELECTCLIPPATH:
                break;

            case GDI32.EMR_BITBLT:
                {
                    // Get the X, Y
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();
                    int width = aRecord.NextInt32();
                    int height = aRecord.NextInt32();

                    // Now create a pixbuff on the specified size
                    PixelBuffer pixBuff = new PixelBuffer(width, height);
                    int dataSize = aRecord.NextInt32();

                    // Copy the received data into it right pixel data pointer
                    aRecord.CopyTo(pixBuff.Pixels.Data, dataSize);

                    // And finally, call the BitBlt function
                    BitBlt(x,y,pixBuff);
                }
                break;


            case GDI32.EMR_POLYBEZIERTO:
                break;


            case GDI32.EMR_POLYBEZIER:
                {
                    Point[] points = UnpackPoints(aRecord);

                    // Now we have everything, so call the call
                    PolyBezier(points);
                }
                break;

            case GDI32.EMR_POLYGON:
                {
                    Point[] points = UnpackPoints(aRecord);

                    // Now we have everything, so call the call
                    Polygon(points);
                }
                break;

            case GDI32.EMR_POLYPOLYGON:
                break;


            case GDI32.EMR_POLYLINE:
                {
                    Point[] points = UnpackPoints(aRecord);

                    // Now we have everything, so call the call
                    PolyLine(points);
                }
                break;

            case GDI32.EMR_POLYLINETO:
                {
                    Point[] points = UnpackPoints(aRecord);

                    //PolyLineTo(points);
                }
                break;

            case GDI32.EMR_POLYPOLYLINE:
                break;

            case GDI32.EMR_POLYTEXTOUTA:
            case GDI32.EMR_POLYTEXTOUTW:
                break;


            case GDI32.EMR_EXTTEXTOUTA:
            case GDI32.EMR_EXTTEXTOUTW:
                {
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();
                    int strLength = aRecord.NextInt32();
                    string text = (string)aRecord;
                    DrawString(x, y, text);
                }
                break;

            case GDI32.EMR_EXTCREATEFONTINDIRECTW:
                {
                    LOGFONT newFont = new LOGFONT();

                    int faceNameLength = aRecord.NextInt32();
                    newFont.lfFaceName = aRecord.NextUtf8String(faceNameLength);
                    newFont.lfHeight = aRecord.NextInt32();
                    newFont.lfCharSet = aRecord.NextByte();
                    newFont.lfClipPrecision = aRecord.NextByte();
                    newFont.lfEscapement = aRecord.NextInt32();
                    newFont.lfItalic = aRecord.NextByte();
                    newFont.lfOrientation = aRecord.NextInt32();
                    newFont.lfOutPrecision = aRecord.NextByte();
                    newFont.lfPitchAndFamily = aRecord.NextByte();
                    newFont.lfQuality = aRecord.NextByte();
                    newFont.lfStrikeOut = aRecord.NextByte();
                    newFont.lfUnderline = aRecord.NextByte();
                    newFont.lfWeight = aRecord.NextInt32();
                    newFont.lfWidth = aRecord.NextInt32();

                    Guid uniqueID = this.UnpackGuid(aRecord);

                    CreateFont(newFont.lfFaceName, newFont.lfHeight, uniqueID);
                }
                break;


            case GDI32.EMR_CREATEMONOBRUSH:
            case GDI32.EMR_EXTCREATEPEN:
            case GDI32.EMR_CREATEDIBPATTERNBRUSHPT:
                break;

            case GDI32.EMR_FILLRGN:
            case GDI32.EMR_FRAMERGN:
            case GDI32.EMR_INVERTRGN:
            case GDI32.EMR_PAINTRGN:
            case GDI32.EMR_EXTSELECTCLIPRGN:
                break;

            case GDI32.EMR_ALPHABLEND:
                {
                    // Get the X, Y
                    int x = aRecord.NextInt32();
                    int y = aRecord.NextInt32();
                    int width = aRecord.NextInt32();
                    int height = aRecord.NextInt32();

                    int srcX = aRecord.NextInt32();
                    int srcY = aRecord.NextInt32();
                    int srcWidth = aRecord.NextInt32();
                    int srcHeight = aRecord.NextInt32();

                    byte alpha = aRecord.NextByte();

                    // Now create a pixbuff on the specified size
                    int buffWidth = aRecord.NextInt32();
                    int buffHeight = aRecord.NextInt32();
                    PixelBuffer pixBuff = new PixelBuffer(buffWidth, buffHeight);
                    int dataSize = aRecord.NextInt32();

                    // Copy the received data into it right pixel data pointer
                    aRecord.CopyTo(pixBuff.Pixels.Data, dataSize);

                    // And finally, call the BitBlt function
                    AlphaBlend(x,y,width,height, pixBuff,srcX,srcY, srcWidth,srcHeight,alpha);
                }
                break;

            case GDI32.EMR_STRETCHBLT:
            case GDI32.EMR_MASKBLT:
            case GDI32.EMR_PLGBLT:
            case GDI32.EMR_SETDIBITSTODEVICE:
            case GDI32.EMR_STRETCHDIBITS:
            case GDI32.EMR_TRANSPARENTBLT:
                break;


            case GDI32.EMR_GDICOMMENT:
            case GDI32.EMR_GLSRECORD:
            case GDI32.EMR_GLSBOUNDEDRECORD:
                break;

            case GDI32.EMR_SETLAYOUT:
                break;

            case GDI32.EMR_PIXELFORMAT:
                break;

            case GDI32.EMR_CREATECOLORSPACE:
            case GDI32.EMR_SETCOLORSPACE:
            case GDI32.EMR_DELETECOLORSPACE:
            case GDI32.EMR_COLORCORRECTPALETTE:
            case GDI32.EMR_SETICMMODE:
            case GDI32.EMR_SETICMPROFILEA:
            case GDI32.EMR_SETICMPROFILEW:
            case GDI32.EMR_COLORMATCHTOTARGETW:
            case GDI32.EMR_CREATECOLORSPACEW:
                break;

            case GDI32.EMR_RESERVED_105:            // These will likely never show up
            case GDI32.EMR_RESERVED_106:
            case GDI32.EMR_RESERVED_107:
            case GDI32.EMR_RESERVED_108:
            case GDI32.EMR_RESERVED_109:
            case GDI32.EMR_RESERVED_110:
            case GDI32.EMR_RESERVED_117:
            case GDI32.EMR_RESERVED_119:
            case GDI32.EMR_RESERVED_120:
            case GDI32.EMR_POLYBEZIER16:    // Probably no real need to implement these
            case GDI32.EMR_POLYBEZIERTO16:
            case GDI32.EMR_POLYGON16:
            case GDI32.EMR_POLYPOLYGON16:
            case GDI32.EMR_POLYLINE16:
            case GDI32.EMR_POLYLINETO16:
            case GDI32.EMR_POLYPOLYLINE16:
            case GDI32.EMR_POLYDRAW16:
            default:
                //if (CommandReceived != null)
                //    CommandReceived(aRecord);
                break;
        }
    }
        public override bool GdiDrawString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Rectangle rtDraw)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    rtDraw);

                if (false == b)
                {
                    return false;
                }

                using (Pen pen2 = new Pen(m_clrOutline2, m_nThickness1 + m_nThickness2))
                {
                    pen2.LineJoin = LineJoin.Round;
                    pGraphics.DrawPath(pen2, pPath);
                }
                using (Pen pen1 = new Pen(m_clrOutline1, m_nThickness1))
                {
                    pen1.LineJoin = LineJoin.Round;
                    pGraphics.DrawPath(pen1, pPath);
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        pGraphics.FillPath(brush, pPath);
                    }
                }
                else
                {
                    pGraphics.FillPath(m_brushText, pPath);
                }
            }
            return true;
        }
Example #48
0
 private void cboFonts_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     try
     {
         if (!m_Loaded || cboFonts.SelectedIndex < 0) return;
         var lf = (LOGFONT)e.AddedItems[0];
         var logF = new LOGFONT();
         logF.Init();
         logF.SetFontFace(lf.lfFaceName);
         logF.SetFontSize((int) cboFontSize.SelectedItem);
         m_Group.Font = logF;
         PNStatic.DrawSkinlessPreview(m_Group, brdFrame, blkCaption, brdBody, blkBody);
         if (lstSkins.SelectedIndex >= 0)
         {
             PNStatic.DrawSkinPreview(m_Group, m_Group.Skin, imgSkin);
         }
     }
     catch (Exception ex)
     {
         PNStatic.LogException(ex);
     }
 }
Example #49
0
        private void OnPaint(object sender, PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

            //Drawing the back ground color
            Color m_clrBkgd = Color.FromArgb(255, 255, 255);
            SolidBrush brushBkgnd = new SolidBrush(m_clrBkgd);
            e.Graphics.FillRectangle(brushBkgnd, 0, 0, this.ClientSize.Width, this.ClientSize.Width);

            PngOutlineText m_PngOutlineText = new PngOutlineText();
            m_PngOutlineText.SetPngImage(new Bitmap(ClientSize.Width, ClientSize.Height));
            m_PngOutlineText.TextGradOutline(
                Color.FromArgb(255, 128, 64),
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 255, 128, 255),
                10);
            m_PngOutlineText.EnableReflection(false);

            m_PngOutlineText.EnableShadow(true);
            //Rem to SetNullShadow() to release memory if a previous shadow has been set.
            m_PngOutlineText.SetNullShadow();
            m_PngOutlineText.Shadow(
                Color.FromArgb(128, 0, 0, 0), 8,
                new Point(4, 4));
            LOGFONT m_LogFont = new LOGFONT();
            m_LogFont.lfFaceName = "Arial Black";
            m_LogFont.lfHeight = -48;

            m_LogFont.lfOrientation = 0;
            m_LogFont.lfEscapement = 0;
            m_LogFont.lfItalic = false;
            float fStartX = 0.0f;
            float fStartY = 0.0f;
            float fDestWidth = 0.0f;
            float fDestHeight = 0.0f;
            m_PngOutlineText.GdiMeasureString(
                e.Graphics,
                m_LogFont,
                "TEXT DESIGNER",
                new Point(10, 10),
                ref fStartX,
                ref fStartY,
                ref fDestWidth,
                ref fDestHeight);
            m_PngOutlineText.SetShadowBkgd(m_clrBkgd, (int)fDestWidth+10, (int)fDestHeight+10);
            LinearGradientBrush gradientBrush = new LinearGradientBrush(new RectangleF(fStartX, fStartY, fDestWidth - fStartX, fDestHeight - fStartY),
                    Color.FromArgb(255, 128, 64), Color.FromArgb(255, 0, 0), LinearGradientMode.Vertical);
            m_PngOutlineText.TextGradOutline(
                gradientBrush,
                Color.FromArgb(255, 64, 0, 64),
                Color.FromArgb(255, 255, 128, 255),
                10);

            m_PngOutlineText.GdiDrawString(
                e.Graphics,
                m_LogFont,
                "TEXT DESIGNER",
                new Point(10, 10));

            e.Graphics.DrawImage(m_PngOutlineText.GetPngImage(), new Point(0, 0));

            brushBkgnd.Dispose();
            e.Graphics.Dispose();
        }
        public override bool GdiDrawString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Rectangle rtDraw)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    rtDraw);

                if (false == b)
                {
                    return false;
                }

                List<Color> list = new List<Color>();
                CalculateGradient(
                    m_clrOutline1,
                    m_clrOutline2,
                    m_nThickness,
                    list);
                for (int i = m_nThickness; i >= 1; --i)
                {
                    System.Drawing.Color clr = list[i - 1];
                    using (Pen pen = new Pen(clr, i))
                    {
                        pen.LineJoin = LineJoin.Round;
                        pGraphics.DrawPath(pen, pPath);
                    }
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        pGraphics.FillPath(brush, pPath);
                    }
                }
                else
                {
                    pGraphics.FillPath(m_brushText, pPath);
                }
            }
            return true;
        }
        public override bool GdiDrawString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Point ptDraw)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    ptDraw);

                if (false == b)
                {
                    return false;
                }

                using (Pen pen = new Pen(m_clrOutline, m_nThickness))
                {
                    if (m_bRoundedEdge)
                        pen.LineJoin = LineJoin.Round;
                    pGraphics.DrawPath(pen, pPath);
                }
            }
            return true;
        }
Example #52
0
 internal static extern IntPtr CreateFontIndirect(ref LOGFONT pLogFont);
Example #53
0
        public static bool GetStringPath(
            System.Drawing.Graphics pGraphics,
            System.Drawing.Drawing2D.GraphicsPath ppPath,
            string pszText,
            LOGFONT plf,
            System.Drawing.Rectangle rtDraw)
        {
            IntPtr hDC = pGraphics.GetHdc();

            int nPrevMode = SetBkMode(hDC, TRANSPARENT);

            // create and select it
            IntPtr hFont = CreateFontIndirect(plf);
            if (null == hFont)
            return false;
            IntPtr hOldFont = (IntPtr)SelectObject(hDC, hFont);

            RECT rect = new RECT(rtDraw);

            // use a path to record how the text was drawn
               	const uint DT_CENTER = 0x00000001;

            BeginPath(hDC);
            DrawText(hDC, pszText, pszText.Length, ref rect, DT_CENTER);
            EndPath(hDC);

            // Find out how many points are in the path. Note that
            // for long strings or complex fonts, this number might be
            // gigantic!
            int nNumPts = GetPath(hDC, null, null, 0);
            if (nNumPts == 0)
            return false;

            // Allocate memory to hold points and stroke types from
            // the path.
            POINT[] lpPoints = new POINT[nNumPts];
            byte[] lpTypes = new byte[nNumPts];

            // Now that we have the memory, really get the path data.
            nNumPts = GetPath(hDC, lpPoints, lpTypes, nNumPts);

            // If it worked, draw the lines. Win95 and Win98 don't support
            // the PolyDraw API, so we use our own member function to do
            // similar work. If you're targeting only Windows NT, you can
            // use the PolyDraw() API and avoid the COutlineView::PolyDraw()
            // member function.

            if (nNumPts != -1)
            PolyDraw(ppPath, lpPoints, lpTypes, nNumPts);

            // Put back the old font
            SelectObject(hDC, hOldFont);
            DeleteObject(hFont);
            SetBkMode(hDC, nPrevMode);

            pGraphics.ReleaseHdc(hDC);

            return true;
        }
Example #54
0
        public OpenTypeFontStyle(FastColoredTextBox fctb, LOGFONT font)
            : base(null, null, FontStyle.Regular)
        {
            this.font = font;
            //measure font
            using (var gr = fctb.CreateGraphics())
            {
                var HDC = gr.GetHdc();

                var fontHandle = CreateFontIndirect(font);
                var f = SelectObject(HDC, fontHandle);

                var measureSize = new Size(0, 0);

                try
                {
                    GetTextExtentPoint(HDC, "M", 1, ref measureSize);
                }
                finally
                {
                    DeleteObject(SelectObject(HDC, f));
                    gr.ReleaseHdc(HDC);
                }

                fctb.CharWidth = measureSize.Width;
                fctb.CharHeight = measureSize.Height + fctb.LineInterval;
                fctb.NeedRecalc(true, true);
            }
        }
        /// <summary>
        /// Sets the font attributes to be used for text within the preview handler.
        /// </summary>
        /// <param name="plf">A pointer to a LOGFONTW Structure containing the necessary attributes for the font to use.</param>
        /// <returns>
        /// If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
        /// </returns>
        int IPreviewHandlerVisuals.SetFont(ref LOGFONT plf)
        {
            //  DebugLog key events.
            Log("IPreviewHandlerVisuals.SetFont called.");

            //  Call the virtual function.
            try
            {
                LOGFONT logfont = plf;
                OnPreviewHostThread(
                    () =>
                        {
                            //  Call the abstract function.
                            if (previewHandlerControl != null)
                                previewHandlerControl.SetVisualsFont(Font.FromLogFont(logfont));
                        });
            }
            catch (Exception exception)
            {
                //  DebugLog the error.
                LogError("An exception occured when setting the font.", exception);
                throw;
            }

            //  Return success.
            return WinError.S_OK;
        }
Example #56
0
 public static extern IntPtr CreateFontIndirect(LOGFONT lpLogFont);
        public override bool GdiDrawString(
            System.Drawing.Graphics pGraphics,
            LOGFONT pLogFont,
            string pszText,
            System.Drawing.Rectangle rtDraw)
        {
            using (GraphicsPath pPath = new GraphicsPath(System.Drawing.Drawing2D.FillMode.Winding))
            {
                bool b = GDIPath.GetStringPath(
                    pGraphics,
                    pPath,
                    pszText,
                    pLogFont,
                    rtDraw);

                if (false == b)
                {
                    return false;
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        pGraphics.FillPath(brush, pPath);
                    }
                }
                else
                {
                    pGraphics.FillPath(m_brushText, pPath);
                }
            }
            return true;
        }
Example #58
0
	public static extern int GetObject( IntPtr hgdiobj, int cbBuffer, out LOGFONT lpvObject );
            public LOGFONT( LOGFONT lf )
            {
                if (lf == null)
                {
                    throw new ArgumentNullException("lf");
                }

                this.lfHeight           = lf.lfHeight;
                this.lfWidth            = lf.lfWidth;
                this.lfEscapement       = lf.lfEscapement;
                this.lfOrientation      = lf.lfOrientation;
                this.lfWeight           = lf.lfWeight;
                this.lfItalic           = lf.lfItalic;
                this.lfUnderline        = lf.lfUnderline;
                this.lfStrikeOut        = lf.lfStrikeOut;
                this.lfCharSet          = lf.lfCharSet;
                this.lfOutPrecision     = lf.lfOutPrecision;
                this.lfClipPrecision    = lf.lfClipPrecision;
                this.lfQuality          = lf.lfQuality;
                this.lfPitchAndFamily   = lf.lfPitchAndFamily;
                this.lfFaceName         = lf.lfFaceName;
            }
Example #60
0
        private void buildList(){
            // Need an HDC to pass to EnumFontFamilies
            IntPtr hwnd = GetDesktopWindow();
            IntPtr hdc = GetDC(hwnd);

            LOGFONT logFont = new LOGFONT();

            enumFontDelegate = new EnumFontDelegate(EnumFontFamiliesExProc);
            fpEnumProc = Marshal.GetFunctionPointerForDelegate(enumFontDelegate);

            EnumFontFamilies(hdc, null, fpEnumProc, IntPtr.Zero);

            // We got a list of the major families.  Copy the list,
            // then clear it so we can go back and grab all the individual fonts.
            List<string> fontFamilies = new List<string>();
            fontFamilies.AddRange(fontNames);
            fontNames.Clear();

            foreach(string fontFamily in fontFamilies)
            {
                EnumFontFamilies(hdc, fontFamily, fpEnumProc, IntPtr.Zero);
            }

            ReleaseDC(hdc);

            foreach(string s in fontNames)
            {
                //listBox1.Items.Add(s);
            }
        }