Exemplo n.º 1
0
        /// <summary>
        /// Converts the PDFX.FontStyle to a System.Drawing.FontStyle
        /// </summary>
        /// <param name="fontStyle">The PDFX.FontStyle</param>
        /// <returns>A comparable System.Drawing.FontStyle</returns>
        public static System.Drawing.FontStyle GetDrawingStyle(FontStyle fontStyle)
        {
            System.Drawing.FontStyle fs = System.Drawing.FontStyle.Regular;
            if ((fontStyle & FontStyle.Bold) > 0)
            {
                fs |= System.Drawing.FontStyle.Bold;
            }

            if ((fontStyle & FontStyle.Italic) > 0)
            {
                fs |= System.Drawing.FontStyle.Italic;
            }

            return(fs);
        }
Exemplo n.º 2
0
        public bool DrawString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int fontSize,
            string strText,
            System.Drawing.Point ptDraw,
            System.Drawing.StringFormat strFormat)
        {
            int nOffset = Math.Abs(m_nOffsetX);

            if (Math.Abs(m_nOffsetX) == Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetX);
            }
            else if (Math.Abs(m_nOffsetX) > Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetY);
            }
            else if (Math.Abs(m_nOffsetX) < Math.Abs(m_nOffsetY))
            {
                nOffset = Math.Abs(m_nOffsetX);
            }

            for (int i = 0; i < nOffset; ++i)
            {
                GraphicsPath path = new GraphicsPath();
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize,
                               new Point(ptDraw.X + ((i * (-m_nOffsetX)) / nOffset), ptDraw.Y + ((i * (-m_nOffsetY)) / nOffset)),
                               strFormat);

                Pen pen = new Pen(m_clrOutline, m_nThickness);
                pen.LineJoin = LineJoin.Round;
                graphics.DrawPath(pen, path);

                if (m_bClrText)
                {
                    SolidBrush brush = new SolidBrush(m_clrText);
                    graphics.FillPath(brush, path);
                }
                else
                {
                    graphics.FillPath(m_brushText, path);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
 protected virtual void SelectFont(System.Drawing.Font font, System.Drawing.FontStyle fontStyle)
 {
     if (font != null)
     {
         this.font      = font;
         this.fontStyle = fontStyle;
         object fontKey = this.GetFontKey(font);
         this.fontInfos = (FontInfos)this.fontTable[fontKey];
         if (this.fontInfos == null)
         {
             this.fontInfos = this.CreateFontInfos(font);
             this.fontTable.Add(fontKey, this.fontInfos);
         }
         this.fontInfos.InitStyle(font.Style);
     }
 }
Exemplo n.º 4
0
        private static System.Drawing.FontStyle ToGdiStyle(TKGameUtilities.Graphics.Font.FontStyle style)
        {
            if (style == FontStyle.Regular)
            {
                return(System.Drawing.FontStyle.Regular);
            }

            System.Drawing.FontStyle result = 0;

            result |= ((style & FontStyle.Bold) > 0 ? System.Drawing.FontStyle.Bold : 0);
            result |= ((style & FontStyle.Italic) > 0 ? System.Drawing.FontStyle.Italic : 0);
            result |= ((style & FontStyle.Strikeout) > 0 ? System.Drawing.FontStyle.Strikeout : 0);
            result |= ((style & FontStyle.Underline) > 0 ? System.Drawing.FontStyle.Underline : 0);

            return(result);
        }
Exemplo n.º 5
0
        private static TKGameUtilities.Graphics.Font.FontStyle ToOurStyle(System.Drawing.FontStyle gdiStyle)
        {
            if (gdiStyle == System.Drawing.FontStyle.Regular)
            {
                return(FontStyle.Regular);
            }

            FontStyle result = 0;

            result |= ((gdiStyle & System.Drawing.FontStyle.Bold) > 0 ? FontStyle.Bold : 0);
            result |= ((gdiStyle & System.Drawing.FontStyle.Italic) > 0 ? FontStyle.Italic : 0);
            result |= ((gdiStyle & System.Drawing.FontStyle.Strikeout) > 0 ? FontStyle.Strikeout : 0);
            result |= ((gdiStyle & System.Drawing.FontStyle.Underline) > 0 ? FontStyle.Underline : 0);

            return(result);
        }
Exemplo n.º 6
0
        public bool DrawString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int nfontSize,
            string strText,
            System.Drawing.Rectangle rtDraw,
            System.Drawing.StringFormat strFormat)
        {
            if (m_bEnableShadow && m_pShadowStrategy != null)
            {
                m_pShadowStrategy.DrawString(
                    graphics,
                    fontFamily,
                    fontStyle,
                    nfontSize,
                    strText,
                    new System.Drawing.Rectangle(rtDraw.X + m_ptShadowOffset.X, rtDraw.Y + m_ptShadowOffset.Y, rtDraw.Width, rtDraw.Height),
                    strFormat);
            }

            if (m_bEnableShadow && m_pBkgdBitmap != null && m_pFontBodyShadow != null)
            {
                RenderFontShadow(
                    graphics,
                    fontFamily,
                    fontStyle,
                    nfontSize,
                    strText,
                    new System.Drawing.Rectangle(rtDraw.X + m_ptShadowOffset.X, rtDraw.Y + m_ptShadowOffset.Y, rtDraw.Width, rtDraw.Height),
                    strFormat);
            }

            if (m_pTextStrategy != null)
            {
                return(m_pTextStrategy.DrawString(
                           graphics,
                           fontFamily,
                           fontStyle,
                           nfontSize,
                           strText,
                           rtDraw,
                           strFormat));
            }

            return(false);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Renders the <see cref="Duality.Resources.Font"/> using the specified system font family.
        /// </summary>
        private RenderedFontData RenderGlyphs(FontFamily fontFamily, float emSize, FontStyle style, FontCharSet extendedSet, bool antialiasing, bool monospace)
        {
            // Determine System.Drawing font style
            SysDrawFontStyle systemStyle = SysDrawFontStyle.Regular;

            if (style.HasFlag(FontStyle.Bold))
            {
                systemStyle |= SysDrawFontStyle.Bold;
            }
            if (style.HasFlag(FontStyle.Italic))
            {
                systemStyle |= SysDrawFontStyle.Italic;
            }

            // Create a System.Drawing font
            SysDrawFont internalFont = null;

            if (fontFamily != null)
            {
                try { internalFont = new SysDrawFont(fontFamily, emSize, systemStyle); }
                catch (Exception e)
                {
                    Log.Editor.WriteError(
                        "Failed to create System Font '{1} {2}, {3}' for rendering Duality Font glyphs: {0}",
                        Log.Exception(e),
                        fontFamily.Name,
                        emSize,
                        style);
                }
            }

            // If creating the font failed, fall back to a default one
            if (internalFont == null)
            {
                internalFont = new SysDrawFont(FontFamily.GenericMonospace, emSize, systemStyle);
            }

            // Render the font's glyphs
            using (internalFont)
            {
                return(this.RenderGlyphs(
                           internalFont,
                           FontCharSet.Default.MergedWith(extendedSet),
                           antialiasing,
                           monospace));
            }
        }
Exemplo n.º 8
0
        private void CreateFontTexture(MiyagiSystem system, SD.FontStyle fontStyle)
        {
            using (var pfc = new PrivateFontCollection())
            {
                pfc.AddFontFile(this.FileName);

                int leading = this.Leading;
                using (SD.Bitmap fontBitmap = CreateFontBitmap(pfc.Families[0], fontStyle, this.Size, this.Resolution, ref leading, this.codePoints, this.GlyphCoordinates))
                {
                    this.Leading = leading;
                    GlobalGlyphCoordinates[this.TextureName] = this.GlyphCoordinates;
                    GlobalLeadings[this.TextureName]         = this.Leading;
                    this.TextureHandle = system.Backend.CreateTexture(this.TextureName, new Size(fontBitmap.Size.Width, fontBitmap.Size.Height));
                    system.Backend.WriteToTexture(fontBitmap.ToByteArray(), this.TextureHandle);
                }
            }
        }
Exemplo n.º 9
0
        private static Eto.Drawing.FontStyle WFFontStyleToEtoFontStyle(System.Drawing.FontStyle fontStyle)
        {
            switch (fontStyle)
            {
            case FontStyle.Bold:
                return(Eto.Drawing.FontStyle.Bold);

            case FontStyle.Regular:
                return(Eto.Drawing.FontStyle.None);

            case FontStyle.Italic:
                return(Eto.Drawing.FontStyle.Italic);

            default:
                return(Eto.Drawing.FontStyle.None);
            }
        }
Exemplo n.º 10
0
        //internal static XGlyphTypeface TryGetXGlyphTypeface(string familyName, XFontStyle style)
        //{
        //    string name = MakeName(familyName, style);

        //    XGlyphTypeface typeface;
        //    _global._typefaces.TryGetValue(name, out typeface);
        //    return typeface;
        //}

#if GDI
        internal static GdiFont TryCreateFont(string name, double size, GdiFontStyle style, out XFontSource fontSource)
        {
            fontSource = null;
            try
            {
                GdiPrivateFontCollection pfc = Singleton._privateFontCollection;
                if (pfc == null)
                {
                    return(null);
                }
#if true
                string key = MakeKey(name, (XFontStyle)style);
                if (Singleton._fontSources.TryGetValue(key, out fontSource))
                {
                    GdiFont font = new GdiFont(name, (float)size, style, GraphicsUnit.World);
#if DEBUG_
                    Debug.Assert(StringComparer.OrdinalIgnoreCase.Compare(name, font.Name) == 0);
                    Debug.Assert(font.Bold == ((style & GdiFontStyle.Bold) != 0));
                    Debug.Assert(font.Italic == ((style & GdiFontStyle.Italic) != 0));
#endif
                    return(font);
                }
                return(null);
#else
                foreach (GdiFontFamily family in pfc.Families)
                {
                    if (string.Compare(family.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        GdiFont font = new GdiFont(family, (float)size, style, GraphicsUnit.World);
                        if (string.Compare(font.Name, name, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            // Style simulation is not implemented in GDI+.
                            // Use WPF build.
                        }
                        return(font);
                    }
                }
#endif
            }
            catch (Exception ex)
            {
                // Ignore exception and return null.
                Debug.WriteLine(ex.ToString());
            }
            return(null);
        }
Exemplo n.º 11
0
 public System.Drawing.Font GetWindowsFont()
 {
     System.Drawing.FontStyle fs = (FontStyle == Rdl.Engine.Style.FontStyleEnum.Italic) ? System.Drawing.FontStyle.Italic : System.Drawing.FontStyle.Regular;
     if (FontWeight >= Rdl.Engine.Style.FontWeightEnum.Bold)
     {
         fs |= System.Drawing.FontStyle.Bold;
     }
     if (TextDecoration == Rdl.Engine.Style.TextDecorationEnum.Underline)
     {
         fs |= System.Drawing.FontStyle.Underline;
     }
     if (TextDecoration == Rdl.Engine.Style.TextDecorationEnum.LineThrough)
     {
         fs |= System.Drawing.FontStyle.Strikeout;
     }
     return(new Font(FontFamily, (float)FontSize.points, fs, GraphicsUnit.Point));
 }
Exemplo n.º 12
0
        public bool SetFont(string familyName, float emSize, System.Drawing.FontStyle fontStyle = FontStyle.Regular)
        {
            font.Name = familyName;
            font.Size = (decimal)emSize;
            switch (fontStyle)
            {
            case FontStyle.Regular:
                font.Bold          = false;
                font.Italic        = false;
                font.Strikethrough = false;
                font.Underline     = false;
                break;

            case FontStyle.Bold:
                font.Bold          = true;
                font.Italic        = false;
                font.Strikethrough = false;
                font.Underline     = false;
                break;

            case FontStyle.Italic:
                font.Bold          = false;
                font.Italic        = true;
                font.Strikethrough = false;
                font.Underline     = false;
                break;

            case FontStyle.Strikeout:
                font.Bold          = false;
                font.Italic        = false;
                font.Strikethrough = true;
                font.Underline     = false;
                break;

            case FontStyle.Underline:
                font.Bold          = false;
                font.Italic        = false;
                font.Strikethrough = false;
                font.Underline     = true;
                break;
            }
            textSymbol.Font = font as stdole.IFontDisp;
            base.Symbol     = textSymbol;
            Update();
            return(true);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Renders the <see cref="Duality.Resources.Font"/> using the specified system font family.
        /// </summary>
        public static void RenderGlyphs(this DualityFont font, FontFamily fontFamily, FontRenderGlyphCharSet extendedSet)
        {
            // Determine System.Drawing font style
            SysDrawFontStyle style = SysDrawFontStyle.Regular;

            if (font.Style.HasFlag(FontStyle.Bold))
            {
                style |= SysDrawFontStyle.Bold;
            }
            if (font.Style.HasFlag(FontStyle.Italic))
            {
                style |= SysDrawFontStyle.Italic;
            }

            // Create a System.Drawing font
            SysDrawFont internalFont = null;

            if (fontFamily != null)
            {
                try { internalFont = new SysDrawFont(fontFamily, font.Size, style); }
                catch (Exception e)
                {
                    Log.Editor.WriteError(
                        "Failed to create System Font '{1} {2}, {3}' for rendering Duality Font glyphs: {0}",
                        Log.Exception(e),
                        fontFamily.Name,
                        font.Size,
                        style);
                }
            }

            // If creating the font failed, fall back to a default one
            if (internalFont == null)
            {
                internalFont = new SysDrawFont(FontFamily.GenericMonospace, font.Size, style);
            }

            // Render the font's glyphs
            using (internalFont)
            {
                RenderGlyphs(
                    font,
                    internalFont,
                    DefaultCharSet.MergedWith(extendedSet));
            }
        }
        public override bool DrawString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int fontSize,
            string strText,
            System.Drawing.Point ptDraw,
            System.Drawing.StringFormat strFormat)
        {
            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize, ptDraw, strFormat);

                List <Color> list = new List <Color>();
                if (m_GradientType == GradientType.Sinusoid)
                {
                    CalculateCurvedGradient(m_clrOutline1, m_clrOutline2, m_nThickness, list);
                }
                else
                {
                    CalculateGradient(m_clrOutline1, m_clrOutline2, m_nThickness, list);
                }

                if (m_bClrText)
                {
                    using (SolidBrush brush = new SolidBrush(m_clrText))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
                else
                {
                    graphics.FillPath(m_brushText, path);
                }

                for (int i = m_nThickness; i >= 1; --i)
                {
                    using (Pen pen1 = new Pen(list[i - 1], i))
                    {
                        pen1.LineJoin = LineJoin.Round;
                        graphics.DrawPath(pen1, path);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 15
0
        private void cmdBold_Click(System.Object sender, System.EventArgs e)
        {
            if ((txtReports.SelectionFont != null))
            {
                System.Drawing.Font      fntCurrentFont  = txtReports.SelectionFont;
                System.Drawing.FontStyle fstNewFontStyle = default(System.Drawing.FontStyle);

                if (txtReports.SelectionFont.Bold == true)
                {
                    fstNewFontStyle = txtReports.SelectionFont.Style & FontStyle.Bold;
                }
                else
                {
                    fstNewFontStyle = txtReports.SelectionFont.Style | FontStyle.Bold;
                }
                txtReports.SelectionFont = new Font(fntCurrentFont.FontFamily, fntCurrentFont.Size, fstNewFontStyle);
            }
        }
Exemplo n.º 16
0
        public override bool GetFontFile(string fontName, int fontSize, System.Drawing.FontStyle style, out string fileName)
        {
            fileName = null;

            System.Drawing.Font fnt = new System.Drawing.Font(fontName, fontSize, style, System.Drawing.GraphicsUnit.Point);

            var names = GetFontNames(fnt);

            foreach (var name in names)
            {
                if (fontFileMap.TryGetValue(name.Name, out fileName))
                {
                    break;
                }
            }
            //Check if requested Font != Default Font
            return(fnt.OriginalFontName == System.Drawing.FontFamily.GenericSansSerif.Name || fnt.OriginalFontName == fnt.Name);
        }
Exemplo n.º 17
0
        private bool TryGetFont(IPDFDocument doc, PDFContextBase context, out PDFFontDefinition definition)
        {
            System.Drawing.FontStyle style = System.Drawing.FontStyle.Regular;
            if (this.FontBold)
            {
                style |= System.Drawing.FontStyle.Bold;
            }
            if (this.FontItalic)
            {
                style |= System.Drawing.FontStyle.Italic;
            }

            string name = this.FontFamily.FamilyName;

            PDFFontFactory.TryEnsureFont(doc, context, this.Source, name, style, out definition);

            return(null != definition);
        }
Exemplo n.º 18
0
        private EntityObject ExportText(GeoObject.Text text)
        {
            System.Drawing.FontStyle fs = System.Drawing.FontStyle.Regular;
            if (text.Bold)
            {
                fs |= System.Drawing.FontStyle.Bold;
            }
            if (text.Italic)
            {
                fs |= System.Drawing.FontStyle.Italic;
            }
            System.Drawing.Font  font = new System.Drawing.Font(text.Font, 1000.0f, fs);
            netDxf.Entities.Text res  = new netDxf.Entities.Text(text.TextString, Vector2.Zero, text.TextSize * 1000 / font.Height, new TextStyle(text.Font + ".ttf"));
            ModOp toText = ModOp.Fit(GeoPoint.Origin, new GeoVector[] { GeoVector.XAxis, GeoVector.YAxis, GeoVector.ZAxis }, text.Location, new GeoVector[] { text.LineDirection.Normalized, text.GlyphDirection.Normalized, text.LineDirection.Normalized ^ text.GlyphDirection.Normalized });

            // res.TransformBy(Matrix4(toText)); // easier than setting normal and rotation
            return(res);
        }
Exemplo n.º 19
0
 // 粗体按钮设置
 private void boldButton_Click(object sender, EventArgs e)
 {
     System.Drawing.FontStyle fs = FontStyle.Regular;
     if (boldButton.FlatStyle == FlatStyle.Flat)
     {
         boldButton.FlatStyle = FlatStyle.Standard;
         boldButton.BackColor = Color.White;
         fs = System.Drawing.FontStyle.Bold;
         SetFont(fs, '-');
     }
     else
     {
         boldButton.FlatStyle = FlatStyle.Flat;
         boldButton.BackColor = Color.Silver;
         fs = System.Drawing.FontStyle.Bold;
         SetFont(fs, '+');
     }
 }
Exemplo n.º 20
0
        public static SizedFontProperties CreateSizedFontProperties(this AppSettings.ToolsSection toolSettings, IFontMap fontMap)
        {
            FontProperties fontProperties;
            FontWeight     bold;

            PaintDotNet.DirectWrite.FontStyle italic;
            string displayName = toolSettings.Text.FontFamilyName.Value;

            string[] namesToTry = new string[] { displayName, "Segoe UI", "Arial" };
            try
            {
                fontProperties = fontMap.GetFontProperties(namesToTry);
            }
            catch (NoFontException)
            {
                fontProperties = new FontProperties(displayName, string.Empty, FontWeight.Normal, FontStretch.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, TextDecorations.None);
            }
            System.Drawing.FontStyle style = toolSettings.Text.FontStyle.Value;
            FontWeight weight = fontProperties.Weight;

            if (style.HasFlag(System.Drawing.FontStyle.Bold) && (weight <= FontWeight.DemiBold))
            {
                bold = FontWeight.Bold;
            }
            else
            {
                bold = weight;
            }
            FontStretch stretch = fontProperties.Stretch;

            PaintDotNet.DirectWrite.FontStyle style2 = fontProperties.Style;
            if (style.HasFlag(System.Drawing.FontStyle.Italic) && (style2 == PaintDotNet.DirectWrite.FontStyle.Normal))
            {
                italic = PaintDotNet.DirectWrite.FontStyle.Italic;
            }
            else
            {
                italic = style2;
            }
            TextDecorations decorations = (fontProperties.Decorations | (style.HasFlag(System.Drawing.FontStyle.Underline) ? TextDecorations.Underline : TextDecorations.None)) | (style.HasFlag(System.Drawing.FontStyle.Strikeout) ? TextDecorations.Strikethrough : TextDecorations.None);
            float           dipSize     = (toolSettings.Text.FontSize.Value * 96f) / 72f;

            return(new SizedFontProperties(new FontProperties(fontProperties.DisplayName, fontProperties.FontFamilyName, bold, stretch, italic, decorations), dipSize));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Metoda vygeneruje fyzický font odpovídající aktuálním datům.
        /// Tento objekt se MUSÍ používat v using patternu, je to new instance vytvořená výhradně pro účel této metody (nejde o objekt z cache).
        /// </summary>
        /// <returns></returns>
        public Font CreateNewFont()
        {
            System.Drawing.FontStyle fontStyle =
                (this.Bold ? System.Drawing.FontStyle.Bold : System.Drawing.FontStyle.Regular) |
                (this.Italic ? System.Drawing.FontStyle.Italic : System.Drawing.FontStyle.Regular) |
                (this.Underline ? System.Drawing.FontStyle.Underline : System.Drawing.FontStyle.Regular);
            float emSize;

            if (this.FontFamilyName != null)
            {
                emSize = Application.App.Zoom.Value * (this.FontEmSize ?? 9f);
                return(new Font(this.FontFamilyName, emSize, fontStyle));
            }

            Font prototype = GetFontPrototype(this.FontType);

            emSize = prototype.Size * _ToRange(Application.App.Zoom.Value * this.SizeRatio);
            return(new Font(prototype.FontFamily, emSize, fontStyle));
        }
Exemplo n.º 22
0
        /// <summary>
        /// Use the font dialog to select a font.
        /// </summary>
        /// <param name="font">
        /// An array with the initial font selected.
        /// It has the same format as the return array, and can be an empty array "".
        /// </param>
        /// <returns>An array with the font properties.
        /// result[1] is Font name
        /// result[2] is Font size
        /// result[3] is Font bold ("True" or "False")
        /// result[4] is Font italic ("True" or "False")
        /// </returns>
        public static Primitive Font(Primitive font)
        {
            string result = "";

            try
            {
                ThreadStart start = delegate
                {
                    System.Windows.Forms.FontDialog dlg = new System.Windows.Forms.FontDialog();
                    if (Microsoft.SmallBasic.Library.Array.GetItemCount(font) == 4)
                    {
                        System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
                        if (font[3])
                        {
                            fontStyle |= System.Drawing.FontStyle.Bold;
                        }
                        if (font[4])
                        {
                            fontStyle |= System.Drawing.FontStyle.Italic;
                        }
                        System.Drawing.Font _Font = new System.Drawing.Font(font[1], font[2], fontStyle);
                        dlg.Font = _Font;
                    }
                    if (dlg.ShowDialog(Utilities.ForegroundHandle()) == System.Windows.Forms.DialogResult.OK)
                    {
                        result += "1=" + Utilities.ArrayParse(dlg.Font.Name) + ";";
                        result += "2=" + Utilities.ArrayParse(dlg.Font.Size.ToString(CultureInfo.InvariantCulture)) + ";";
                        result += "3=" + (dlg.Font.Bold ? "True" : "False") + ";";
                        result += "4=" + (dlg.Font.Italic ? "True" : "False") + ";";
                    }
                };
                Thread thread = new Thread(start);
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                StartPosition(null, "Font");
                thread.Join();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
            return(Utilities.CreateArrayMap(result));
        }
Exemplo n.º 23
0
        // Match Current Style and Justification to Button Settings
        private void UpdateFontStyle()
        {
            System.Drawing.Font      currentfont = this.rtbMainForm1.SelectionFont;
            System.Drawing.FontStyle newstyle    = FontStyle.Regular;

            if (cbMainFormBold.Checked)
            {
                newstyle = newstyle | FontStyle.Bold;
            }
            if (cbmainFormItalic.Checked)
            {
                newstyle = newstyle | FontStyle.Italic;
            }
            if (cb2MainFormUnderline.Checked)
            {
                newstyle = newstyle | FontStyle.Underline;
            }
            if (rbMainFormLeft.Checked)
            {
                rtbMainForm1.SelectionAlignment = HorizontalAlignment.Left;
            }
            else
            {
                if (rbMainFormCenter.Checked)
                {
                    rtbMainForm1.SelectionAlignment = HorizontalAlignment.Center;
                }
                else
                {
                    rtbMainForm1.SelectionAlignment = HorizontalAlignment.Right;
                }
            }
            try
            {
                rtbMainForm1.SelectionFont = new System.Drawing.Font(currentfont.FontFamily,
                                                                     currentfont.Size, newstyle); // add test to be sure font supports the current style*/
            }
            catch (Exception e)
            {
            }

            this.rtbMainForm1.Focus();
        }
Exemplo n.º 24
0
        public WinFormsTypeface(string name, double size, TypefaceStyle style)
        {
            SD.FontStyle sdfs = SD.FontStyle.Regular;
            if ((style & TypefaceStyle.Bold) != 0)
            {
                sdfs |= SD.FontStyle.Bold;
            }
            if ((style & TypefaceStyle.Italic) != 0)
            {
                sdfs |= SD.FontStyle.Italic;
            }
            if ((style & TypefaceStyle.Underline) != 0)
            {
                sdfs |= SD.FontStyle.Underline;
            }

            Font     = new SD.Font(name, (float)size, sdfs);
            ownsfont = true;
        }
Exemplo n.º 25
0
        public IFontStyleInfo ProduceNewFontStyleInfo(
            string FamilyName,
            float size,
            System.Drawing.FontStyle theStyle)
        {
            GDIFontStyle result = new GDIFontStyle();

            string  sig   = GetSignature(FamilyName, size, theStyle);
            GDIFont found = FindFont(sig);

            if (found == null)
            {
                found = new GDIFont(FamilyName, size, theStyle);
                AddFont(found);
            }
            result.Font = found;

            return(result);
        }
Exemplo n.º 26
0
        public bool MeasureString(
            System.Drawing.Graphics graphics,
            System.Drawing.FontFamily fontFamily,
            System.Drawing.FontStyle fontStyle,
            int fontSize,
            string strText,
            System.Drawing.Rectangle rtDraw,
            System.Drawing.StringFormat strFormat,
            ref float fStartX,
            ref float fStartY,
            ref float fDestWidth,
            ref float fDestHeight)
        {
            using (GraphicsPath path = new GraphicsPath())
            {
                path.AddString(strText, fontFamily, (int)fontStyle, fontSize, rtDraw, strFormat);

                fDestWidth  = rtDraw.Width;
                fDestHeight = rtDraw.Height;
                bool b = GDIPath.MeasureGraphicsPath(graphics, path, ref fStartX, ref fStartY, ref fDestWidth, ref fDestHeight);

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

                float pixelThick  = 0.0f;
                float pixelThick2 = 0.0f;
                float fStartX2    = 0.0f;
                float fStartY2    = 0.0f;
                b = GDIPath.ConvertToPixels(graphics, m_nThickness, 0.0f, ref fStartX2, ref fStartY2, ref pixelThick, ref pixelThick2);

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

                fDestWidth  += pixelThick;
                fDestHeight += pixelThick;
            }
            return(true);
        }
Exemplo n.º 27
0
        // Get font family metric information.
        public void GetFontFamilyMetrics(GenericFontFamilies genericFamily,
                                         String name,
                                         System.Drawing.FontStyle style,
                                         out int ascent, out int descent,
                                         out int emHeight, out int lineSpacing)
        {
            // X doesn't have family metric information, so return
            // dummy information based on the generic font family.
            switch (genericFamily)
            {
            case GenericFontFamilies.SansSerif:
            default:
            {
                // Metrics for "Arial".
                ascent      = 1854;
                descent     = 434;
                emHeight    = 2048;
                lineSpacing = 2355;
            }
            break;

            case GenericFontFamilies.Serif:
            {
                // Metrics for "Times New Roman".
                ascent      = 1825;
                descent     = 443;
                emHeight    = 2048;
                lineSpacing = 2355;
            }
            break;

            case GenericFontFamilies.Monospace:
            {
                // Metrics for "Courier New".
                ascent      = 1705;
                descent     = 615;
                emHeight    = 2048;
                lineSpacing = 2320;
            }
            break;
            }
        }
Exemplo n.º 28
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="familyName"></param>
 /// <param name="emSize"></param>
 /// <param name="style"></param>
 /// <param name="fontSource"></param>
 /// <returns></returns>
 public static GdiFont TryCreateFont(string familyName, double emSize, GdiFontStyle style, out XFontSource fontSource)
 {
     fontSource = null;
     try
     {
         string key = MakeKey(familyName, (XFontStyle)style);
         // TODO: avoid to let system choose font while missing familyName
         GdiFont font = new GdiFont(familyName, (float)emSize, style, GraphicsUnit.World);
         fontSource = XFontSource.GetOrCreateFromGdi(key, font);
         Debug.Assert(fontSource != null);
         return(font);
     }
     catch (Exception ex)
     {
         // Ignore exception and return null.
         Debug.WriteLine(ex.ToString());
         Debug.Assert(true);
     }
     return(null);
 }
Exemplo n.º 29
0
        /// <summary>取得 Windows.Controls.Control 之對應的 Drawing.Font</summary>
        /// <param name="ctrl">欲轉換的 <see cref="Control"/></param>
        /// <returns><see cref="Win32Draw.Font"/></returns>
        public static Win32Draw.Font GetFont(this Control ctrl)
        {
            return(ctrl.TryInvoke(
                       () => {
                string fontFamily = ctrl.FontFamily.Source;
                float emSize = (float)ctrl.FontSize;
                Win32Draw.FontStyle fontStyle = Win32Draw.FontStyle.Regular;
                if (ctrl.FontStyle == FontStyles.Italic)
                {
                    fontStyle = Win32Draw.FontStyle.Italic;
                }
                if (ctrl.FontWeight == FontWeights.Bold)
                {
                    fontStyle |= Win32Draw.FontStyle.Bold;
                }

                return new Win32Draw.Font(fontFamily, emSize, fontStyle);
            }
                       ));
        }
Exemplo n.º 30
0
        public static GdiFont CreateFont(string familyName, double emSize, GdiFontStyle style, out XFontSource fontSource)
        {
            fontSource = null;
            // ReSharper disable once JoinDeclarationAndInitializer
            GdiFont font;

            // Use font resolver in CORE build. XPrivateFontCollection exists only in GDI and WPF build.
#if GDI
            // Try private font collection first.
            font = XPrivateFontCollection.TryCreateFont(familyName, emSize, style, out fontSource);
            if (font != null)
            {
                // Get font source is different for this font because Win32 does not know it.
                return(font);
            }
#endif
            // Create ordinary Win32 font.
            font = new GdiFont(familyName, (float)emSize, style, GraphicsUnit.World);
            return(font);
        }
Exemplo n.º 31
0
 private static Font CreateFont(string fontName, float fontSize, FontStyle fontStyle, GraphicsUnit graphicsUnit)
 {
     try
     {
         return new Font(fontName, fontSize, fontStyle, graphicsUnit);
     }
     catch
     {
         return new Font("Arial", 3, fontStyle, graphicsUnit);
     }
 }
Exemplo n.º 32
0
        private void Form1_Load(object sender, EventArgs e)
        {
            FileName = "";
            textBoxMain.Multiline = true;
            textBoxMain.ScrollBars = ScrollBars.Vertical;
            textBoxMain.Dock = DockStyle.Fill;
            saveFileDialog1.Filter = "テキスト文章|*.txt|すべてのファイル|*.*";
            fontDialog1.ShowEffects = false;
            fontDialog1.AllowScriptChange = false;

            Microsoft.Win32.RegistryKey regKey =
                Microsoft.Win32.Registry.CurrentUser.
                CreateSubKey(RegistryKey);
            // ファイルパス設定の読み込み
            FilePath = regKey.GetValue("FilePath",
                System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.MyDocuments)).
                ToString();
            // フォント設定の読み込み
            string name =
                regKey.GetValue("FontName", "MS ゴシック").ToString();
            Single size = Single.Parse(regKey.GetValue("FontSize", 12).ToString());
            bool bold = bool.Parse(regKey.GetValue("FontBold", false).ToString());
            bool italic = bool.Parse(regKey.GetValue("FontItalic", false).ToString());
            System.Drawing.FontStyle style = new System.Drawing.FontStyle();
            if (bold) style = System.Drawing.FontStyle.Bold;
            if (italic) style = style ^ System.Drawing.FontStyle.Italic;
            textBoxMain.Font = new System.Drawing.Font(name, size, style);

            // ウィンドウが小さくなり過ぎないように
            const int initialWidth = 400;
            const int initialHeight = 200;
            this.MinimumSize = new System.Drawing.Size(
                initialWidth, initialHeight);

            // ウィンドウの位置と大きさを読み込み
            const int initialLeft = 100;
            const int initialTop = 100;
            int l = int.Parse(regKey.GetValue("Left", initialLeft).ToString());
            int t = int.Parse(regKey.GetValue("Top", initialTop).ToString());
            int w = int.Parse(regKey.GetValue("Width", initialWidth).ToString());
            int h = int.Parse(regKey.GetValue("Height", initialHeight).ToString());
            if (l < Screen.GetWorkingArea(this).Left ||
                l >= Screen.GetWorkingArea(this).Right)
                l = initialLeft;
            if (t < Screen.GetWorkingArea(this).Top ||
                t >= Screen.GetWorkingArea(this).Bottom)
                t = initialTop;
            this.SetDesktopBounds(l, t, w, h);

            // 不要なものは無効にする
            MenuItemEdit_DropDownOpened(sender, e);

            // 印刷設定
            printDialog1.Document = printDocument1;

            // 印刷プレビュー
            printPreviewDialog1.Document = printDocument1;

            // コマンド引数でファイル名を受け取る
            if (1 < Environment.GetCommandLineArgs().Length)
            {
                string[] args = Environment.GetCommandLineArgs();
                LoadFile(args[1]);
            }
        }
Exemplo n.º 33
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            //RTBRecord.Focus();
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";

            try
            {
                face = msg.GetTag("face").ToString();
            }
            catch (Exception)
            {
                face = "";
            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown == null)
                    {
                        emotionDropdown = new EmotionDropdown();
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;
                    }
                    else
                    {
                        String img_str = msg.GetTag(imageContent[1]);
                        try
                        {

                            if (msg.From.Bare == XmppConn.MyJID.Bare)
                            {
                                image = Image.FromFile(Util.sendImage + imageContent[1].ToString() + ".gif");
                            }
                            else
                            {
                                image = Image.FromFile(Util.receiveImage + imageContent[1].ToString() + ".gif");
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    this.RTBRecord.addGifControl(imageContent[1], image);
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {

                this.RTBRecord.AppendText(msgtext + "\n");
            }
            //RTBRecord.Focus();
            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
            //this.RTBRecord.Focus();
        }
Exemplo n.º 34
0
 /// <summary>
 /// Use the font dialog to select a font.
 /// </summary>
 /// <param name="font">
 /// An array with the initial font selected.
 /// It has the same format as the return array, and can be an empty array "".
 /// </param>
 /// <returns>An array with the font properties.
 /// result[1] is Font name
 /// result[2] is Font size
 /// result[3] is Font bold ("True" or "False")
 /// result[4] is Font italic ("True" or "False")
 /// </returns>
 public static Primitive Font(Primitive font)
 {
     string result = "";
     try
     {
         ThreadStart start = delegate
         {
             System.Windows.Forms.FontDialog dlg = new System.Windows.Forms.FontDialog();
             if (Microsoft.SmallBasic.Library.Array.GetItemCount(font) == 4)
             {
                 System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
                 if (font[3]) fontStyle |= System.Drawing.FontStyle.Bold;
                 if (font[4]) fontStyle |= System.Drawing.FontStyle.Italic;
                 System.Drawing.Font _Font = new System.Drawing.Font(font[1], font[2], fontStyle);
                 dlg.Font = _Font;
             }
             if (dlg.ShowDialog(Utilities.ForegroundHandle()) == System.Windows.Forms.DialogResult.OK)
             {
                 result += "1=" + Utilities.ArrayParse(dlg.Font.Name) + ";";
                 result += "2=" + Utilities.ArrayParse(dlg.Font.Size.ToString(CultureInfo.InvariantCulture)) + ";";
                 result += "3=" + (dlg.Font.Bold ? "True" : "False") + ";";
                 result += "4=" + (dlg.Font.Italic ? "True" : "False") + ";";
             }
         };
         Thread thread = new Thread(start);
         thread.SetApartmentState(ApartmentState.STA);
         thread.Start();
         StartPosition(null, "Font");
         thread.Join();
     }
     catch (Exception ex)
     {
         Utilities.OnError(Utilities.GetCurrentMethod(), ex);
     }
     return Utilities.CreateArrayMap(result);
 }
Exemplo n.º 35
0
 public TextContext()
 {
     fontFamily = new System.Drawing.FontFamily("Arial");
     fontStyle = System.Drawing.FontStyle.Regular;
     nfontSize = 20;
     pszText = null;
     ptDraw = new System.Drawing.Point(0, 0);
     strFormat = new System.Drawing.StringFormat();
 }
Exemplo n.º 36
0
		private void Form1_Load(object sender, EventArgs e) {

			this.FileName = "";

			this.textBoxMain.Multiline = true;
			this.textBoxMain.ScrollBars = ScrollBars.Vertical;

			this.saveFileDialog1.Filter = "テキスト文書|*.txt|すべてのファイル|*.*";
			fontDialog1.ShowEffects = false;
			fontDialog1.AllowScriptChange = false;

			Microsoft.Win32.RegistryKey regKey =
				Microsoft.Win32.Registry.CurrentUser.CreateSubKey(RegistryKey);
			_filePath = regKey.GetValue("FilePath", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)).
				ToString();

			//TODO:リスト21「33フォントの設定を覚える」
			string name = regKey.GetValue("FontName", "MS ゴシック").ToString();
			Single size = Single.Parse(regKey.GetValue("FontSize", 12).ToString());
			bool bold = bool.Parse(regKey.GetValue("FontBold", false).ToString());
			bool italic = bool.Parse(regKey.GetValue("FontItalic", false).ToString());
			System.Drawing.FontStyle style = new System.Drawing.FontStyle();
			if (bold) style = System.Drawing.FontStyle.Bold;
			if (italic) style = style ^ System.Drawing.FontStyle.Italic;
			textBoxMain.Font = new System.Drawing.Font(name, size, style);
			label1.Font = new System.Drawing.Font(name, size, style);

			//TODO:リスト22「34 ウィンドウが小さくなりすぎないように」
			const int initialWidth = 400;
			const int initialHeight = 200;
			this.MinimumSize = new System.Drawing.Size(initialWidth, initialHeight);

			//TODO:リスト23「35 ウィンドウの位置と大きさを覚える」
			const int initialLeft = 100;
			const int initialTop = 100;
			int l = int.Parse(regKey.GetValue("Left", initialLeft).ToString());
			int t = int.Parse(regKey.GetValue("Top", initialTop).ToString());
			int w = int.Parse(regKey.GetValue("Width", initialWidth).ToString());
			int h = int.Parse(regKey.GetValue("Height", initialHeight).ToString());
			if (l < Screen.GetWorkingArea(this).Left || l >= Screen.GetWorkingArea(this).Right)
				l = initialLeft;
			if (t < Screen.GetWorkingArea(this).Top || t >= Screen.GetWorkingArea(this).Bottom)
				t = initialTop;
			this.SetDesktopBounds(l, t, w, h);

			if (1 < Environment.GetCommandLineArgs().Length) {
				string[] args = Environment.GetCommandLineArgs();
				LoadFile(args[1]);
			}
			//TODO:リスト29「41 不要なものは無効にする」
			MenuItemEdit_DropDownOpening(sender, e);

			//TODO:リスト34「46 印刷ダイアログを出す」
			printDialog1.Document = printDocument1;

			//TODO:リスト35「47 印刷プレビューを可能にする」
			printPreviewDialog1.Document = printDocument1;

			this.DispRowNo();
		}
Exemplo n.º 37
0
 internal void SetFontStyle(System.Drawing.FontStyle value)
 {
     if (this._fontStyle != value)
     {
         this._fontStyle = value;
         this.DisposeFont();
     }
 }
Exemplo n.º 38
0
        public static GdiFont CreateFont(string familyName, double emSize, GdiFontStyle style, out XFontSource fontSource)
        {
            fontSource = null;
            // ReSharper disable once JoinDeclarationAndInitializer
            GdiFont font;

            // Use font resolver in CORE build. XPrivateFontCollection exists only in GDI and WPF build.
#if GDI
            // Try private font collection first.
            font = XPrivateFontCollection.TryCreateFont(familyName, emSize, style, out fontSource);
            if (font != null)
            {
                // Get font source is different for this font because Win32 does not know it.
                return font;
            }
#endif
            // Create ordinary Win32 font.
            font = new GdiFont(familyName, (float)emSize, style, GraphicsUnit.World);
            return font;
        }
Exemplo n.º 39
0
        private void LoadSettings()
        {
            /*key验证杜宾用*/
            //int iCertNum = 0;
            //GetCert.GetCertNum(out iCertNum);

            //if (iCertNum == 0)
            //{
            //    MsgBox.Show(this, "CSS&IM", "请插入启动钥匙后在启动程序。", MessageBoxButtons.OK);
            //    Application.Exit();
            //    return;
            //}
            /*key验证杜宾用*/

            if (System.IO.File.Exists(string.Format(CSS.IM.UI.Util.Path.SettingsFilename, HistoryFilename)))
            {
                Document login_doc = new Document();
                login_doc.LoadFile(string.Format(CSS.IM.UI.Util.Path.SettingsFilename, HistoryFilename));
                Settings.Login login = login_doc.RootElement.SelectSingleElement(typeof(Settings.Login)) as Settings.Login;
                Settings.ServerInfo serverInfo = login_doc.RootElement.SelectSingleElement(typeof(Settings.ServerInfo)) as Settings.ServerInfo;
                if (login.Save)
                {
                    txt_name.Texts = login.Jid == null ? "" : login.Jid.ToString();
                    txt_pswd.Texts = login.Password == null ? "" : login.Password;
                    if (ISAutoLogin)
                    {
                        chb_autu.Checked = login.Auto;
                    }
                    else
                    {
                        chb_autu.Checked = false;
                    }

                    chb_save.Checked = login.Save;
                }
                Program.ServerIP = serverInfo.ServerIP;
                Program.Port = serverInfo.ServerPort;
                CSS.IM.UI.Util.Path.Initial = login.InitIal;
            }

            if (System.IO.File.Exists(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, HistoryFilename)))
            {

                Document local_doc = new Document();
                local_doc.LoadFile(string.Format(CSS.IM.UI.Util.Path.ConfigFilename, HistoryFilename));

                Settings.Paths local_path = local_doc.RootElement.SelectSingleElement(typeof(Settings.Paths)) as Settings.Paths;
                CSS.IM.UI.Util.Path.MsgPath = local_path.MsgPath;
                CSS.IM.UI.Util.Path.MsgSwitch = local_path.SelectSingleElement("MsgPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.SystemPath = local_path.SystemPath;
                CSS.IM.UI.Util.Path.SystemSwitch = local_path.SelectSingleElement("SystemPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.CallPath = local_path.CallPath;
                CSS.IM.UI.Util.Path.CallSwitch = local_path.SelectSingleElement("CallPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.FolderPath = local_path.FolderPath;
                CSS.IM.UI.Util.Path.FolderSwitch = local_path.SelectSingleElement("FolderPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.GlobalPath = local_path.GlobalPath;
                CSS.IM.UI.Util.Path.GlobalSwitch = local_path.SelectSingleElement("GlobalPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.InputAlertPath = local_path.InputAlertPath;
                CSS.IM.UI.Util.Path.InputAlertSwitch = local_path.SelectSingleElement("InputAlertPath").GetAttributeBool("Enable");
                CSS.IM.UI.Util.Path.ReveiveSystemNotification = local_path.ReveiveSystemNotification;
                CSS.IM.UI.Util.Path.ChatOpen = local_path.ChatOpen;
                CSS.IM.UI.Util.Path.SendKeyType = local_path.SendKeyType;
                CSS.IM.UI.Util.Path.GetOutMsgKeyTYpe = local_path.GetOutMsgKeyTYpe;
                CSS.IM.UI.Util.Path.ScreenKeyTYpe = local_path.ScreenKeyTYpe;
                CSS.IM.UI.Util.Path.FriendContainerType = local_path.FriendContainerType;

                CSS.IM.UI.Util.Path.DefaultURL = local_path.DefaultURL;
                CSS.IM.UI.Util.Path.EmailURL = local_path.EmailURL;

                SFont font1 = local_doc.RootElement.SelectSingleElement(typeof(Settings.SFont)) as Settings.SFont;
                System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
                System.Drawing.Font ft = null;
                #region 获取字体
                if (font1 != null)
                {
                    try
                    {
                        if (font1.Bold)
                        {
                            fontStyle = System.Drawing.FontStyle.Bold;
                        }
                        if (font1.Italic)
                        {
                            fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                        }
                        if (font1.Strikeout)
                        {
                            fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                        }
                        if (font1.Underline)
                        {
                            fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                        }

                        ft = new System.Drawing.Font(font1.Name, font1.Size, fontStyle);
                    }
                    catch (Exception)
                    {
                        ft = txt_name.Font;
                    }
                }
                else
                {
                    ft = txt_name.Font;
                }

                #endregion
                CSS.IM.UI.Util.Path.SFong = ft;

                SColor color1 = local_doc.RootElement.SelectSingleElement(typeof(Settings.SColor)) as Settings.SColor;
                #region 获取颜色
                Color cl;
                if (color1 != null)
                {
                    try
                    {
                        byte[] cby = new byte[4];
                        cby[0] = color1.CA;
                        cby[1] = color1.CR;
                        cby[2] = color1.CG;
                        cby[3] = color1.CB;
                        cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

                    }
                    catch
                    {
                        cl = txt_name.ForeColor;
                    }
                }
                else
                {
                    cl = txt_name.ForeColor;
                }

                #endregion
                CSS.IM.UI.Util.Path.SColor = cl;
            }

            Util.RunWhenStart(CSS.IM.UI.Util.Path.Initial, "CSS&IM", Application.StartupPath + @"\CSSIM.exe");

            /*key验证杜宾用*/
            //try
            //{
            //    StringBuilder names = new StringBuilder("");
            //    GetCert.GetCertName(0, 100, names);
            //    txt_name.ReadOn = true;
            //    txt_pswd.ReadOn = true;

            //    txt_name.Texts = names.ToString();
            //    txt_pswd.Texts = "1";
            //    chb_autu.Checked = true;
            //    chb_save.Checked = true;
            //    timer_keyLogin.Enabled = true;
            //}
            //catch (Exception)
            //{

            //}
            /*key验证杜宾用*/
        }
Exemplo n.º 40
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            string sqlstr = "insert into ChatMessageLog (Belong,Jid,[MessageLog],[DateNow])values ({0},{1},{2},{3})";
            sqlstr = String.Format(sqlstr,
                "'" + XmppConn.MyJID.Bare.ToString() + "'",
                "'" + (isSend == true ? msg.To.Bare.ToString() : msg.From.Bare.ToString()) + "'",
                "'" + msg.ToString() + "'",
                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";
            try
            {
                if (msg.GetTag("face")!=null)
                {
                    face = msg.GetTag("face").ToString();
                }
                else
                {
                    face = "";
                }
            }
            catch (Exception)
            {

            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown==null)
                    {
                        emotionDropdown = new EmotionDropdown();
                        emotionDropdown.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = CSS.IM.UI.Util.ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;

                        this.RTBRecord.addGifControl(imageContent[1], image);
                    }
                    else
                    {
                        try
                        {
                            if (isSend)
                            {
                                image = this.rtfSend.findPic(imageContent[1]).Image;
                                this.RTBRecord.addGifControl(imageContent[1], image);

                            }
                            else
                            {
                                image = CSS.IM.UI.Util.ResClass.GetImgRes("wite");
                                this.RTBRecord.addGifControl(imageContent[1] + "_r", image);
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {
                this.RTBRecord.AppendText(msgtext + "\n");
            }

            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
        }
Exemplo n.º 41
0
        private void Form1_Load(object sender, EventArgs e)
        {
            const int initialWidth = 400;
            const int initialHeight = 200;

            this.MinimumSize = new System.Drawing.Size(initialWidth, initialHeight);

            FileName = "";

            textBoxMain.Multiline = true;
            textBoxMain.ScrollBars = ScrollBars.Vertical;
            textBoxMain.Dock = DockStyle.Fill;

            fontDialog1.ShowEffects = false; // 文字飾りをfalse
            fontDialog1.AllowScriptChange = false; // 文字セットをfalse

            saveFileDialog1.Filter = "テキスト文書|*.txt|すべてのファイル|*.*";

            // レジストリからFilePathを取り出す。レジストリにFilePathが無い場合は「マイ ドキュメント」を入れる
            Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(RegistryKey);
            FilePath = regKey.GetValue("FilePath", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)).ToString();

            string name = regKey.GetValue("FontName", "MS ゴシック").ToString();
            Single size = Single.Parse(regKey.GetValue("FontSize", 12).ToString());
            bool bold = bool.Parse(regKey.GetValue("FontBold", false).ToString());
            bool italic = bool.Parse(regKey.GetValue("FontItalic", false).ToString());
            System.Drawing.FontStyle style = new System.Drawing.FontStyle();

            if (bold)
                style = System.Drawing.FontStyle.Bold;
            if (italic)
                style = style ^ System.Drawing.FontStyle.Italic;
            textBoxMain.Font = new System.Drawing.Font(name, size, style);
                

            if (Environment.GetCommandLineArgs().Length > 1)
            {
                string[] args = Environment.GetCommandLineArgs();
                LoadFile(args[1]);
            }
        }
Exemplo n.º 42
0
        //internal static XGlyphTypeface TryGetXGlyphTypeface(string familyName, XFontStyle style)
        //{
        //    string name = MakeName(familyName, style);

        //    XGlyphTypeface typeface;
        //    _global._typefaces.TryGetValue(name, out typeface);
        //    return typeface;
        //}

#if GDI
        internal static GdiFont TryCreateFont(string name, double size, GdiFontStyle style, out XFontSource fontSource)
        {
            fontSource = null;
            try
            {
                GdiPrivateFontCollection pfc = Singleton._privateFontCollection;
                if (pfc == null)
                    return null;
#if true
                string key = MakeKey(name, (XFontStyle)style);
                if (Singleton._fontSources.TryGetValue(key, out fontSource))
                {
                    GdiFont font = new GdiFont(name, (float)size, style, GraphicsUnit.World);
#if DEBUG_
                    Debug.Assert(StringComparer.OrdinalIgnoreCase.Compare(name, font.Name) == 0);
                    Debug.Assert(font.Bold == ((style & GdiFontStyle.Bold) != 0));
                    Debug.Assert(font.Italic == ((style & GdiFontStyle.Italic) != 0));
#endif
                    return font;
                }
                return null;
#else
                foreach (GdiFontFamily family in pfc.Families)
                {
                    if (string.Compare(family.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        GdiFont font = new GdiFont(family, (float)size, style, GraphicsUnit.World);
                        if (string.Compare(font.Name, name, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            // Style simulation is not implemented in GDI+.
                            // Use WPF build.
                        }
                        return font;
                    }
                }
#endif
            }
            catch (Exception ex)
            {
                // Ignore exception and return null.
                Debug.WriteLine(ex.ToString());
            }
            return null;
        }