Exemple #1
0
        /// <summary>
        /// Updates the font family.
        /// </summary>
        /// <param name="fontFamily"></param>
        protected void UpdateFontFamily(FontFamily fontFamily)
        {
            var font = fontFamily.ToString();

            if (font.Contains("Arial"))
            {
                UpdateArialFontFamily();
            }
            else if (font.Contains("Courier"))
            {
                UpdateCourierFontFamily();
            }
            else if (font.Contains("Verdana"))
            {
                UpdateVerdanaFontFamily();
            }
            else if (font.Contains("Webdings"))
            {
                UpdateOtherFontFamily();
            }
            else
            {
                throw new Exception("Font type not supported.");
            }
        }
Exemple #2
0
 private void windows_loading(MainWindow farm_in_put)
 {
     Bold           = farm_in_put.main_Bold;
     Ltalic         = farm_in_put.main_Ltalic;
     Line           = farm_in_put.main_Ltalic;
     size_out       = (int)farm_in_put.Text_in.FontSize;
     FontFamily_put = farm_in_put.Text_in.FontFamily;
     font_show.Text = FontFamily_put.ToString();
     Size_show.Text = size_out.ToString();
 }
Exemple #3
0
 public static double GetFontWidth(string text, CultureInfo cultureInfo, FontFamily fontFamily, double fontSize,
                            FlowDirection leftToRight)
 {
     return
         new FormattedText(text,
                           cultureInfo,
                           leftToRight,
                           new Typeface(fontFamily.ToString()),
                           fontSize,
                           Brushes.Black)
             .Width;
 }
 private void FontFamilyChanged(object sender, SelectionChangedEventArgs e)
 {
     foreach (var item in cbFontFamily.Items)
     {
         System.Windows.Media.FontFamily font = new System.Windows.Media.FontFamily(item.ToString());
         if (font.ToString() == cbFontFamily.SelectedItem.ToString())
         {
             richTextBox.Selection.ApplyPropertyValue(RichTextBox.FontFamilyProperty, font);
             break;
         }
     }
 }
Exemple #5
0
        private void AddFont(FontFamily fontFamily, FontStretch fontStretch, string text)
        {
            var stackPanel = new StackPanel();
            stackPanel.Margin = new Thickness(5);

            stackPanel.Children.Add(NewTextBlock(fontFamily, FontWeights.Normal, FontStretches.Normal, fontFamily.ToString()));

            foreach (var weight in _weights)
            {
                stackPanel.Children.Add(NewTextBlock(fontFamily, weight, fontStretch, weight + ": " + text));
            }

            FontList.Children.Add(stackPanel);
        }
        internal SystemFont(FontFamily rpFontFamily)
        {
            FontFamily = rpFontFamily;

            var rNames = rpFontFamily.FamilyNames;
            string rName;
            if (rNames.TryGetValue(XmlLanguage.GetLanguage("ja-jp"), out rName) ||
                rNames.TryGetValue(XmlLanguage.GetLanguage("zh-cn"), out rName) ||
                rNames.TryGetValue(XmlLanguage.GetLanguage("zh-tw"), out rName) ||
                rNames.TryGetValue(XmlLanguage.GetLanguage("zh-hk"), out rName) ||
                rNames.TryGetValue(XmlLanguage.GetLanguage("en-us"), out rName))
                Name = rName;
            else
                Name = rpFontFamily.ToString();
        }
		void ChangeFontFamily(object sender, RoutedEventArgs e)
		{

            ffamily = btn2.FontFamily;
            str = ffamily.ToString();
			if (str == ("Arial Black"))
			{
				btn2.FontFamily = new FontFamily("Arial");
				btn2.Content = "FontFamily";
			}
			else
			{
				btn2.FontFamily = new FontFamily("Arial Black");
				btn2.Content = "Control font family changes from Arial to Arial Black.";

			}
		}
Exemple #8
0
        /// <summary>
        /// Calculates a maximum font size that will fit in a given space
        /// </summary>
        /// <param name="maximumFontSize">The maximum (and default) font size</param>
        /// <param name="minimumFontSize">The minimum size the font is capped at</param>
        /// <param name="reductionStep">The step to de-increment font size with. A higher step is less expensive, whereas a lower step sizes font with greater accuracy</param>
        /// <param name="text">The string to measure</param>
        /// <param name="fontFamily">The font family the string provided should be measured in</param>
        /// <param name="containerAreaSize">The total area of the containing area for font placement, specified as a size</param>
        /// <param name="containerInnerMargin">An internal margin to specify the distance the font should keep from the edges of the container</param>
        /// <returns>The caculated maximum font size</returns>
        public static Double CalculateMaximumFontSize(Double maximumFontSize, Double minimumFontSize, Double reductionStep, String text, FontFamily fontFamily, Size containerAreaSize, Thickness containerInnerMargin, string CultureInfo)
        {
            // set fontsize to maimumfont size
            Double fontSize = maximumFontSize;

            // holds formatted text - Culture info is setup for US-Engish, this can be changed for different language sets
            FormattedText formattedText = new FormattedText(text, System.Globalization.CultureInfo.GetCultureInfo(CultureInfo), FlowDirection.LeftToRight, new Typeface(fontFamily.ToString()), fontSize, Brushes.Black);

            // hold the maximum internal space allocation as an absolute value
            Double maximumInternalWidth = containerAreaSize.Width - (containerInnerMargin.Left + containerInnerMargin.Right);

            // if measured font is too big for container size, with regard for internal margin
            if (formattedText.WidthIncludingTrailingWhitespace > maximumInternalWidth)
            {
                do
                {
                    // reduce font size by step
                    fontSize -= reductionStep;

                    // set fontsize ready for re-measure
                    formattedText.SetFontSize(fontSize);
                }
                while ((formattedText.WidthIncludingTrailingWhitespace > maximumInternalWidth) && (fontSize > minimumFontSize));

            }
            double maximumInternalHeight = containerAreaSize.Height - (containerInnerMargin.Top + containerInnerMargin.Bottom);
            if (fontSize > maximumInternalHeight)
            {
                 do
                {
                    // reduce font size by step
                    fontSize -= reductionStep;

                    // set fontsize ready for re-measure
                    formattedText.SetFontSize(fontSize);
                }
                 while ((fontSize > maximumInternalHeight) && (fontSize > minimumFontSize));
            }

            // return ammended fontsize
            return fontSize;
        }
		public static Size EstimateTextRenderSize(FontFamily fontFamily, double fontSize, Thickness padding, string content = "Fq")
		{
			var formattedText = new FormattedText(content, CultureInfo.GetCultureInfo("en-us"),
						FlowDirection.LeftToRight, new Typeface(fontFamily.ToString()), fontSize, MaterialPalette.Black000);
			return new Size(formattedText.Width + padding.Left + padding.Right, formattedText.Height + padding.Top + padding.Bottom);
		}
Exemple #10
0
        public override Bitmap Paint()
        {
            ZintNetLib zintNetLib = new ZintNetLib();

            zintNetLib.TextVisible   = _textVisable;
            zintNetLib.Multiplier    = _width;
            zintNetLib.BarcodeHeight = _height;
            zintNetLib.Rotation      = (int)_rotate;
            zintNetLib.CreateBarcode(BarcodeSymbology, Data);
            Font font = new Font(fontfamily, (float)FontSize, (System.Drawing.FontStyle)Enum.ToObject(typeof(System.Drawing.FontStyle), (int)FontStyle));

            if (_fontFamily?.ToString() != fontfamily)
            {
                _fontFamily = new System.Windows.Media.FontFamily(fontfamily);
            }
            zintNetLib.Font          = font;
            zintNetLib.TextAlignment = _textAligment;
            zintNetLib.TextPosition  = _textPosition;
            if (!zintNetLib.IsValid)
            {
                return(null);
            }
            switch (_rotate)
            {
            case EnumRotate._0:
            case EnumRotate._180:
            default:
                using (Bitmap bmBarcode = new Bitmap(10000, 10000))
                {
                    using (Graphics gr = Graphics.FromImage(bmBarcode))
                    {
                        var bcSize = zintNetLib.SymbolSize(gr);
                        zintNetLib.DrawBarcode(gr, new System.Drawing.Point(0, 0));
                        using (Bitmap bmOutput = new Bitmap(bcSize.Width, bcSize.Height))
                        {
                            using (Graphics grOut = Graphics.FromImage(bmOutput))
                            {
                                grOut.Clear(System.Drawing.Color.White);
                                grOut.DrawImage(bmBarcode, 0.0f, 0.0f,
                                                new RectangleF(0.0f, 0.0f, (float)bcSize.Width, (float)bcSize.Height),
                                                GraphicsUnit.Pixel);
                                _imagepixelSize = new System.Windows.Size((float)bcSize.Width, (float)bcSize.Height);
                            }
                            return(new Bitmap(bmOutput));
                        }
                    }
                }

            case EnumRotate._90:
            case EnumRotate._270:
                using (Bitmap bmBarcode = new Bitmap(10000, 10000))
                {
                    using (Graphics gr = Graphics.FromImage(bmBarcode))
                    {
                        var bcSize = zintNetLib.SymbolSize(gr);
                        zintNetLib.DrawBarcode(gr, new System.Drawing.Point(0, 0 + (bcSize.Width - bcSize.Height) / 2));
                        using (Bitmap bmOutput = new Bitmap(bcSize.Height, bcSize.Width))
                        {
                            using (Graphics grOut = Graphics.FromImage(bmOutput))
                            {
                                grOut.Clear(System.Drawing.Color.White);
                                grOut.DrawImage(bmBarcode, 0.0f, 0.0f,
                                                new RectangleF(0.0f + (bcSize.Width - bcSize.Height) / 2, 0.0f, (float)bcSize.Height, (float)bcSize.Width),
                                                GraphicsUnit.Pixel);
                                _imagepixelSize = new System.Windows.Size((float)bcSize.Height, (float)bcSize.Width);
                            }
                            return(new Bitmap(bmOutput));
                        }
                    }
                }
            }
        }
Exemple #11
0
		public static Double CalculateMaximumFontSize (Double maximumFontSize, Double minimumFontSize, Double reductionStep, String text, FontFamily fontFamily, Size containerAreaSize, Thickness containerInnerMargin)
			{
			Double fontSize = maximumFontSize;
			FormattedText formattedText = new FormattedText (text, System.Globalization.CultureInfo.GetCultureInfo ("en-us"), FlowDirection.LeftToRight, new Typeface (fontFamily.ToString ()), fontSize, Brushes.Black);

			Double maximumInternalWidth = containerAreaSize.Width - (containerInnerMargin.Left + containerInnerMargin.Right) * 2;
			Double maximumInternalHeight = containerAreaSize.Height - (containerInnerMargin.Top + containerInnerMargin.Bottom) * 2;
			Geometry TextGeometry = formattedText.BuildGeometry (new Point (0, 0));
			if ((TextGeometry.Bounds.Width >= maximumInternalWidth) || (TextGeometry.Bounds.Height >= maximumInternalHeight))
				{
				do
					{
					fontSize -= reductionStep;
					formattedText.SetFontSize (fontSize);
					TextGeometry = formattedText.BuildGeometry(new Point(0, 0));
					}
				while (((TextGeometry.Bounds.Width >= maximumInternalWidth)
					|| (TextGeometry.Bounds.Height >= maximumInternalHeight)) 
						&& (fontSize > minimumFontSize));
				}
			return fontSize;
			}
Exemple #12
0
 public OneFont(FontFamily family)
 {
     this.Name = family.ToString();
 }
 /// <summary>
 /// 设置文档选区的字体
 /// </summary>
 public static void SetFontFamily(this HtmlDocument document, FontFamily value)
 {
     document.ExecuteCommand("FontName", false, value.ToString());
 }
 /// <summary>
 /// Creates a FontBinding, the name is taken from the font family name
 /// and trimmed if the name includes a location
 /// </summary>
 /// <param name="family">The font family</param>
 public FontBinding(FontFamily family)
 {
     Family = family;
     Name = TrimFontName(Family.ToString());
 }
 public static void Initialize(FontFamily fontFamily, double fontSize) {
     _typeface = new Typeface(fontFamily.ToString());
     _fontSize = fontSize;
 }