Example #1
0
 void WriteColorAttributes(XshdColor color)
 {
     if (color.Foreground != null)
     {
         writer.WriteAttributeString("foreground", color.Foreground.ToString());
     }
     if (color.Background != null)
     {
         writer.WriteAttributeString("background", color.Background.ToString());
     }
     if (color.FontWeight != null)
     {
         writer.WriteAttributeString("fontWeight", FontWeightConverter.ConvertToString(color.FontWeight.Value).ToLowerInvariant());
     }
     if (color.FontStyle != null)
     {
         writer.WriteAttributeString("fontStyle", FontStyleConverter.ConvertToString(color.FontStyle.Value).ToLowerInvariant());
     }
 }
Example #2
0
        public static MigraDoc.DocumentObjectModel.Paragraph ExportFormattedText(string Text, FontWeight fntwt, double FontSize, Brush textcolor, FontStyle fstyle)
        {
            bool isSignifCode = false;

            if (Text.Trim().StartsWith("Signif. codes:"))
            {
                isSignifCode = true;
            }


            string text = Text.Replace(Environment.NewLine, String.Empty).Replace("  ", String.Empty);

            //Font Weight
            MigraDoc.DocumentObjectModel.TextFormat txtformat;
            int                 fwt;
            FontWeight          fw     = fntwt;
            FontWeightConverter fwc    = new FontWeightConverter();
            string              fontwt = fwc.ConvertToString(fw);

            bool isItalic = false;

            if (fstyle != null)
            {
                string s = fwc.ConvertToString(fstyle);
                if (s != null && s.Equals("Italic"))
                {
                    isItalic = true;
                }
            }
            switch (fontwt)
            {
            case "SemiBold":
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.Bold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.Bold;
                }
                break;

            case "Normal":
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold;
                }
                break;

            default:
                if (isItalic)
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold | MigraDoc.DocumentObjectModel.TextFormat.Italic;
                }
                else
                {
                    txtformat = MigraDoc.DocumentObjectModel.TextFormat.NotBold;
                }
                break;
            }


            //Font Color
            System.Windows.Media.Color         fcolor    = (textcolor as SolidColorBrush).Color;
            MigraDoc.DocumentObjectModel.Color fontcolor = new MigraDoc.DocumentObjectModel.Color(fcolor.A, fcolor.R, fcolor.G, fcolor.B);

            //Font Size
            if (FontSize == 0)
            {
                FontSize = 14;
            }

            // Create a new MigraDoc document
            MigraDoc.DocumentObjectModel.Document document = new MigraDoc.DocumentObjectModel.Document();

            // Add a section to the document
            MigraDoc.DocumentObjectModel.Section section = document.AddSection();

            // Add a paragraph to the section
            MigraDoc.DocumentObjectModel.Paragraph paragraph = section.AddParagraph();

            if (isSignifCode)//add 'Notes.' in italics before 'Signif. codes:'
            {
                paragraph.AddFormattedText("Note. ", MigraDoc.DocumentObjectModel.TextFormat.Italic);
            }

            // Add some text to the paragraph
            paragraph.AddFormattedText(Text, txtformat);
            paragraph.Format.Font.Name  = "Times New Roman";
            paragraph.Format.Font.Size  = FontSize;
            paragraph.Format.Font.Color = fontcolor;
            paragraph.AddLineBreak();
            if (isSignifCode)
            {
                paragraph.AddLineBreak(); //add extra linebreak if 'signif code' is printed
            }

            return(paragraph);
        }
Example #3
0
        private void InitText()
        {
            var fwc = new FontWeightConverter();
            var fsc = new FontStyleConverter();

            FontSelector.ItemsSource = Fonts.SystemFontFamilies;
            var fontIndex = -1;

            // Font name...
            if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Name))
            {
                var g = new Graph(null, null);
                _fontName = g.FontFamily.Source;
                Properties.Settings.Default.Plot_Font_Name = _fontName;
            }
            else
            {
                _fontName = Properties.Settings.Default.Plot_Font_Name;
            }

            // Font size...
            if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Size))
            {
                PlotFontSize = 12;
            }
            else
            {
                try
                {
                    PlotFontSize = double.Parse(Properties.Settings.Default.Plot_Font_Size);
                }
                catch
                {
                }
            }

            // Font weight...
            if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Weight))
            {
                PlotFontWeight = (FontWeight)fwc.ConvertFromString("Normal");
            }
            else
            {
                PlotFontWeight = (FontWeight)fwc.ConvertFromString(Properties.Settings.Default.Plot_Font_Weight);
            }

            // Font style...
            if (string.IsNullOrEmpty(Properties.Settings.Default.Plot_Font_Style))
            {
                PlotFontStyle = (FontStyle)fsc.ConvertFromString("Normal");
            }
            else
            {
                PlotFontStyle = (FontStyle)fsc.ConvertFromString(Properties.Settings.Default.Plot_Font_Style);
            }

            foreach (System.Windows.Media.FontFamily ff in FontSelector.Items)
            {
                fontIndex++;
                if (System.String.Compare(ff.Source, _fontName, System.StringComparison.Ordinal) == 0)
                {
                    _fontFamily = ff;
                    break;
                }
            }

            // Font FG color
            if (Properties.Settings.Default.Plot_FG_Color != null)
            {
                _fgBrush = new SolidColorBrush(
                    System.Windows.Media.Color.FromRgb(
                        Properties.Settings.Default.Plot_FG_Color.R,
                        Properties.Settings.Default.Plot_FG_Color.G,
                        Properties.Settings.Default.Plot_FG_Color.B));
            }

            // Init the controls
            FontSelector.SelectedIndex   = fontIndex;
            ComboBoxStyle.SelectedValue  = fsc.ConvertToString(PlotFontStyle);
            ComboBoxWeight.SelectedValue = fwc.ConvertToString(PlotFontWeight);
            SliderFontSize.DataContext   = this;
        }
Example #4
0
        /// <summary>
        /// Serializes the font weight.
        /// </summary>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The serialized font weight.</returns>
        public static string SerializeFontWeight(FontWeight fontWeight)
        {
            var converter = new FontWeightConverter();

            return(converter.ConvertToString(fontWeight));
        }