Ejemplo n.º 1
0
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            bool   isBold         = fontProperties.FontWeight == FontWeights.Bold;
            string fontFolder     = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

            if (fontFamilyName == "Arial" && isBold)
            {
                return(this.GetFontDataFromFontFolder("arialbd.ttf"));
            }
            else if (fontFamilyName == "Arial")
            {
                return(this.GetFontDataFromFontFolder("arial.ttf"));
            }
            else if (fontFamilyName == "Calibri" && isBold)
            {
                return(this.GetFontDataFromFontFolder("calibrib.ttf"));
            }
            else if (fontFamilyName == "Calibri")
            {
                return(this.GetFontDataFromFontFolder("calibri.ttf"));
            }

            return(null);
        }
Ejemplo n.º 2
0
 public ScriptStyle(string name, Color fore, Color back, Font font)
 {
     Name            = name;
     ForegroundColor = ColorSerializetionHelper.Serialize(fore);
     BackgroundColor = ColorSerializetionHelper.Serialize(back);
     FontProperties  = FontSerializetionHelper.Serialize(font);
 }
Ejemplo n.º 3
0
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            bool   isBold         = fontProperties.FontWeight == FontWeights.Bold;
            string fontFolder     = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

            if (fontFamilyName == "Arial" && isBold)
            {
                using (FileStream fileStream = File.OpenRead(fontFolder + "\\arialbd.ttf"))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        return(memoryStream.ToArray());
                    }
                }
            }
            else if (fontFamilyName == "Arial")
            {
                return(this.GetFontDataFromFontFolder("arial.ttf"));
            }
            else if (fontFamilyName == "Calibri" && isBold)
            {
                return(this.GetFontDataFromFontFolder("calibrib.ttf"));
            }
            else if (fontFamilyName == "Calibri")
            {
                return(this.GetFontDataFromFontFolder("calibri.ttf"));
            }

            return(null);
        }
Ejemplo n.º 4
0
 public Ruler() : base(FactorySource.PerThread)
 {
     this.cursorBrush         = new SolidColorBrush();
     this.lineBrush           = new SolidColorBrush();
     this.textBrush           = new SolidColorBrush();
     this.unitsBoxBrush       = new SolidColorBrush();
     this.measurementUnit     = PaintDotNet.MeasurementUnit.Inch;
     this.dpu                 = 96.0;
     this.scaleFactor         = PaintDotNet.ScaleFactor.OneToOne;
     base.UseHwndRenderTarget = true;
     this.tickLabelFontLazy   = new Lazy <SizedFontProperties>(delegate {
         using (IGdiFontMap map = DirectWriteFactory.Instance.GetGdiFontMapRef(true))
         {
             FontProperties fontProperties;
             try
             {
                 fontProperties = map.GetFontProperties(tickLabelFontNames);
             }
             catch (NoFontException)
             {
                 fontProperties = new FontProperties(string.Empty, string.Empty, FontWeight.Normal, FontStretch.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, TextDecorations.None);
             }
             return(new SizedFontProperties(fontProperties, UIUtil.ScaleHeight((float)10.66667f)));
         }
     }, LazyThreadSafetyMode.PublicationOnly);
     using (ISystemFonts fonts = new PaintDotNet.DirectWrite.SystemFonts())
     {
         this.unitsBoxFont = fonts.Menu;
     }
 }
Ejemplo n.º 5
0
        private void ApplyForListBox(ListBox listBox, string _props)
        {
            Dictionary <string, string> properties = GetProperties(_props);
            FontProperties fontProperties          = new FontProperties(8.25f);

            foreach (var property in properties)
            {
                switch (property.Key)
                {
                case "background-color":
                    listBox.BackColor = Color.FromName(property.Value);
                    break;

                case "color":
                    listBox.ForeColor = Color.FromName(property.Value);
                    break;

                case "font-family":
                    FontFamily family = new FontFamily(property.Value);
                    fontProperties.family = family;
                    break;

                case "font-size":
                    float size = (float)Convert.ToDouble(property.Value.Substring(0, property.Value.Length - 2));
                    fontProperties.size = size;
                    break;

                case "font-style":
                    FontStyle f = (FontStyle)Enum.Parse(typeof(FontStyle), property.Value, true);
                    fontProperties.style = f;
                    break;
                }
            }
            listBox.Font = new Font(fontProperties.family, fontProperties.size, fontProperties.style);
        }
Ejemplo n.º 6
0
 public Class31(FontProperties properties)
 {
     this.fontProperties_0 = properties;
     this.string_1         = properties.FaceName.Replace(" ", "-");
     this.idictionary_0    = (IDictionary <ushort, char>) new Dictionary <ushort, char>();
     this.method_0();
 }
Ejemplo n.º 7
0
 public TableFormatter()
 {
     HeaderFont = new FontProperties {
         FontWeight = FontWeights.Bold
     };
     TableCellFont = new FontProperties();
 }
Ejemplo n.º 8
0
 public void AcceptMetafileDescriptorFontProperties(FontProperties fontProperties, PrintContext parameter)
 {
     parameter.WriteLine("Font Properties: {0} entries", fontProperties.Properties.Length);
     parameter.BeginLevel();
     foreach (var property in fontProperties.Properties)
     {
         parameter.WriteLine("{0} ({1}), priority {2}", property.Indicator, property.Name, property.Priority);
     }
     parameter.EndLevel();
 }
Ejemplo n.º 9
0
        public void FontPropertiesTest()
        {
            var fp = new FontProperties {
                TextColorArgb = Color.Red.ToArgb()
            };

            fp.IsBold = fp.IsItalic = fp.IsUnderline = true;
            var font = fp.ToFont();

            Assert.IsNotNull(font);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Get a bitmask of all non-null properties.
        /// </summary>
        private FontProperties CheckWhatIsNotNull()
        {
            FontProperties fp = FontProperties.None;

            if (!_name.IsNull)
            {
                fp |= FontProperties.Name;
            }
            if (!_size.IsNull)
            {
                fp |= FontProperties.Size;
            }
            if (!_bold.IsNull)
            {
                fp |= FontProperties.Bold;
            }
            if (!_italic.IsNull)
            {
                fp |= FontProperties.Italic;
            }
            if (!_underline.IsNull)
            {
                fp |= FontProperties.Underline;
            }
            if (!_color.IsNull)
            {
                fp |= FontProperties.Color;
            }
            if (!_superscript.IsNull)
            {
                fp |= FontProperties.Superscript;
            }
            if (!_subscript.IsNull)
            {
                fp |= FontProperties.Subscript;
            }
            // SRG
            //@{
            if (!_strikethrough.IsNull)
            {
                fp |= FontProperties.Strikethrough;
            }
            if (!_rectangle.IsNull)
            {
                fp |= FontProperties.Rectangle;
            }
            //@}
            return(fp);
        }
Ejemplo n.º 11
0
        public void ApplyUndoAwarePropertyValue(TextRange range, DependencyProperty property, object value)
        {
            if (!range.IsEmpty)
            {
                var bu = new FormatUndo(Document, range, this);
                PushUndoAction(bu, true);

                range.ApplyPropertyValue(property, value);

                bu.UpdateSelectionOffsets(this, range);
            }
            else
            {
                TextRange paragraphRange;

                if (CaretPosition.Paragraph != null)
                {
                    paragraphRange = new TextRange(CaretPosition.Paragraph.ContentStart,
                                                   CaretPosition.Paragraph.ContentEnd);
                }
                else
                {
                    paragraphRange = new TextRange(CaretPosition.DocumentStart,
                                                   CaretPosition.DocumentEnd);
                }

                FontProperties fontProps = new FontProperties(paragraphRange);
                var            bu        = new FormatUndo(Document,
                                                          paragraphRange,
                                                          this);

                int caretPositionStart = Document.ContentStart.GetOffsetToPosition(CaretPosition);
                int caretPositionEnd   = Document.ContentEnd.GetOffsetToPosition(CaretPosition);

                range.ApplyPropertyValue(property, value);

                int newCaretPositionStart = Document.ContentStart.GetOffsetToPosition(CaretPosition);
                int newCaretPositionEnd   = Document.ContentEnd.GetOffsetToPosition(CaretPosition);

                string paragraphRangeText = paragraphRange.Text;
                if (caretPositionStart != newCaretPositionStart || caretPositionEnd != newCaretPositionEnd ||
                    !fontProps.HasSameStyle(paragraphRange))
                {
                    PushUndoAction(bu, true);
                }
            }
            return;
        }
Ejemplo n.º 12
0
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            bool   isBold         = fontProperties.FontWeight == FontWeights.Bold;
            string fontFolder     = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

            if (fontFamilyName == "Franklin Gothic Book" && isBold)
            {
                return(this.GetFontDataFromFontFolder("FRABK.TTF"));
            }
            else if (fontFamilyName == "Franklin Gothic Book")
            {
                return(this.GetFontDataFromFontFolder("FRABK.TTF"));
            }

            return(null);
        }
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            bool   isItalic       = fontProperties.FontStyle == FontStyles.Italic;
            bool   isBold         = fontProperties.FontWeight == FontWeights.Bold;

            if (fontFamilyName == "Algerian")
            {
                return(this.GetFontDataFromFontFolder("ALGER.TTF"));
            }
            else if (fontFamilyName == "Arial")
            {
                return(this.GetFontDataFromFontFolder("arial.ttf"));
            }
            else if (fontFamilyName == "Calibri" && isItalic && isBold)
            {
                return(this.GetFontDataFromFontFolder("calibriz.ttf"));
            }
            else if (fontFamilyName == "Calibri")
            {
                return(this.GetFontDataFromFontFolder("calibri.ttf"));
            }
            else if (fontFamilyName == "Consolas" && isBold)
            {
                return(this.GetFontDataFromFontFolder("consolaz.ttf"));
            }
            else if (fontFamilyName == "Consolas")
            {
                return(this.GetFontDataFromFontFolder("consola.ttf"));
            }
            else if (fontFamilyName == "Lucida Calligraphy")
            {
                return(this.GetFontDataFromFontFolder("LCALLIG.TTF"));
            }
            else if (fontFamilyName == "Malgun Gothic")
            {
                return(this.GetFontDataFromFontFolder("malgun.ttf"));
            }
            else if (fontFamilyName == "Trebuchet MS")
            {
                return(this.GetFontDataFromFontFolder("trebuc.ttf"));
            }

            return(null);
        }
        public UndoFlowDocumentFormatting(OutlinerNote note, int columnId, bool isInlineNote, bool wasSelected)
        {
            __NoteId       = note.Id;
            __ColumnId     = columnId;
            __IsInlineNote = isInlineNote;

            __Before = new MemoryStream();

            FlowDocument flowDocument = (FlowDocument)note.Columns[columnId].ColumnData;

            __FontPropertiesBefore = new FontProperties(flowDocument);

            TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

            range.Save(__Before, DataFormats.Xaml);

            __WasSelected = wasSelected;
        }
Ejemplo n.º 15
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));
        }
        public override void Undo(OutlinerDocument document, TreeListView treeListView)
        {
            OutlinerNote note = document.FindOutlinerNoteById(__NoteId);

            if (note == null)
            {
                return;
            }

            __Before.Seek(0, SeekOrigin.Begin);

            FlowDocument flowDocument;

            if (__IsInlineNote)
            {
                flowDocument = note.InlineNoteDocument;
            }
            else
            {
                flowDocument = (FlowDocument)note.Columns[__ColumnId].ColumnData;
            }

            if (flowDocument == null)
            {
                return;
            }

            TextRange range = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);

            if (__After == null)
            {
                __After = new MemoryStream();
                range.Save(__After, DataFormats.Xaml);
                __FontPropertiesAfter = new FontProperties(flowDocument);
            }
            range.Load(__Before, DataFormats.Xaml);
            __FontPropertiesBefore.ApplyToFlowDocument(flowDocument);

            if (__WasSelected)
            {
                treeListView.MakeActive(note, -1, false);
            }
        }
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            string fontFolder     = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

            if (fontFamilyName == "Segoe UI Light")
            {
                return(this.GetFontDataFromFontFolder("segoeuil.ttf"));
            }
            else if (fontFamilyName == "Cambria")
            {
                return(this.GetFontDataFromFontFolder("cambria.ttc"));
            }
            else if (fontFamilyName == "Segoe UI")
            {
                return(this.GetFontDataFromFontFolder("segoeui.ttf"));
            }

            return(null);
        }
Ejemplo n.º 18
0
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFamilyName = fontProperties.FontFamilyName;
            bool   isItalic       = fontProperties.FontStyle == FontStyles.Italic;
            bool   isBold         = fontProperties.FontWeight == FontWeights.Bold;

            if (fontFamilyName == "Jokerman")
            {
                return(this.GetFontDataFromFontFolder("JOKERMAN.TTF"));
            }
            else if (fontFamilyName == "Arial" && isItalic && isBold)
            {
                return(this.GetFontDataFromFontFolder("arialbi.ttf"));
            }
            else if (fontFamilyName == "Arial")
            {
                return(this.GetFontDataFromFontFolder("arial.ttf"));
            }

            return(null);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Get a bitmask of all non-null properties.
        /// </summary>
        private FontProperties CheckWhatIsNotNull()
        {
            FontProperties fp = FontProperties.None;

            if (!this.name.IsNull)
            {
                fp |= FontProperties.Name;
            }
            if (!this.size.IsNull)
            {
                fp |= FontProperties.Size;
            }
            if (!this.bold.IsNull)
            {
                fp |= FontProperties.Bold;
            }
            if (!this.italic.IsNull)
            {
                fp |= FontProperties.Italic;
            }
            if (!this.underline.IsNull)
            {
                fp |= FontProperties.Underline;
            }
            if (!this.color.IsNull)
            {
                fp |= FontProperties.Color;
            }
            if (!this.superscript.IsNull)
            {
                fp |= FontProperties.Superscript;
            }
            if (!this.subscript.IsNull)
            {
                fp |= FontProperties.Subscript;
            }
            return(fp);
        }
Ejemplo n.º 20
0
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFileName = fontProperties.FontFamilyName + ".ttf";
            string fontFolder   = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            string targetPath   = Path.Combine(fontFolder, fontFileName);

            DirectoryInfo directory = new DirectoryInfo(fontFolder);

            FileInfo[] fontFiles = directory.GetFiles("*.ttf");
            if (fontFiles.Any(s => s.Name.ToLower() == fontFileName.ToLower()))
            {
                using (FileStream fileStream = File.OpenRead(targetPath))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        return(memoryStream.ToArray());
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Converts Font into DDL. Properties with the same value as in an optionally given
        /// font are not serialized.
        /// </summary>
        internal void Serialize(Serializer serializer, Font font)
        {
            if (this.Parent is FormattedText)
            {
                string fontStyle = "";
                if (((FormattedText)this.Parent).style.IsNull)
                {
                    // Check if we can use a DDL keyword.
                    FontProperties notNull = CheckWhatIsNotNull();
                    if (notNull == FontProperties.Size)
                    {
                        serializer.Write("\\fontsize(" + size.ToString() + ")");
                        return;
                    }
                    else if (notNull == FontProperties.Bold && bold.Value)
                    {
                        serializer.Write("\\bold");
                        return;
                    }
                    else if (notNull == FontProperties.Italic && italic.Value)
                    {
                        serializer.Write("\\italic");
                        return;
                    }
                    else if (notNull == FontProperties.Color)
                    {
                        serializer.Write("\\fontcolor(" + color.ToString() + ")");
                        return;
                    }
                }
                else
                {
                    fontStyle = "(\"" + ((FormattedText)this.Parent).Style + "\")";
                }

                //bool needBlank = false;  // nice, but later...
                serializer.Write("\\font" + fontStyle + "[");

                if (!this.name.IsNull && this.name.Value != "")
                {
                    serializer.WriteSimpleAttribute("Name", this.Name);
                }

#if DEBUG // Test
                if (!this.size.IsNull && this.Size != 0 && this.Size.Point == 0)
                {
                    this.GetType();
                }
#endif
                if ((!this.size.IsNull))
                {
                    serializer.WriteSimpleAttribute("Size", this.Size);
                }

                if (!this.bold.IsNull)
                {
                    serializer.WriteSimpleAttribute("Bold", this.Bold);
                }

                if (!this.italic.IsNull)
                {
                    serializer.WriteSimpleAttribute("Italic", this.Italic);
                }

                if (!this.underline.IsNull)
                {
                    serializer.WriteSimpleAttribute("Underline", this.Underline);
                }

                if (!this.superscript.IsNull)
                {
                    serializer.WriteSimpleAttribute("Superscript", this.Superscript);
                }

                if (!this.subscript.IsNull)
                {
                    serializer.WriteSimpleAttribute("Subscript", this.Subscript);
                }

                if (!this.color.IsNull)
                {
                    serializer.WriteSimpleAttribute("Color", this.Color);
                }

                serializer.Write("]");
            }
            else
            {
                int pos = serializer.BeginContent("Font");

#if true
                //!!!newTHHO 26.07.2007 begin
                // Don't write null values if font is null.
                // Do write null values if font is not null!
                if ((!this.name.IsNull && this.Name != String.Empty && font == null) ||
                    (font != null && !this.name.IsNull && this.Name != String.Empty && this.Name != font.Name))
                {
                    serializer.WriteSimpleAttribute("Name", this.Name);
                }

                // Test
                if (!this.size.IsNull && this.Size != 0 && this.Size.Point == 0)
                {
                    this.GetType();
                }

                if (!this.size.IsNull &&
                    (font == null || (font != null && this.Size != font.Size)))
                {
                    serializer.WriteSimpleAttribute("Size", this.Size);
                }
                //NBool and NEnum have to be compared directly to check whether the value Null is
                if (!this.bold.IsNull && font == null || (font != null && this.Bold != font.Bold))
                {
                    serializer.WriteSimpleAttribute("Bold", this.Bold);
                }

                if (!this.italic.IsNull && font == null || (font != null && this.Italic != font.Italic))
                {
                    serializer.WriteSimpleAttribute("Italic", this.Italic);
                }

                if (!this.underline.IsNull && font == null || (font != null && this.Underline != font.Underline))
                {
                    serializer.WriteSimpleAttribute("Underline", this.Underline);
                }

                if (!this.superscript.IsNull && font == null || (font != null && this.Superscript != font.Superscript))
                {
                    serializer.WriteSimpleAttribute("Superscript", this.Superscript);
                }

                if (!this.subscript.IsNull && font == null || (font != null && this.Subscript != font.Subscript))
                {
                    serializer.WriteSimpleAttribute("Subscript", this.Subscript);
                }

                if (!this.color.IsNull && (font == null || (font != null && this.Color.Argb != font.Color.Argb)))// && this.Color.RGB != Color.Transparent.RGB)
                {
                    serializer.WriteSimpleAttribute("Color", this.Color);
                }
                //!!!newTHHO 26.07.2007 begin
#else
                if ((!this.name.IsNull && this.Name != String.Empty) && (font == null || this.Name != font.Name))
                {
                    serializer.WriteSimpleAttribute("Name", this.Name);
                }

                if (!this.size.IsNull && (font == null || this.Size != font.Size))
                {
                    serializer.WriteSimpleAttribute("Size", this.Size);
                }
                //NBool and NEnum have to be compared directly to check whether the value Null is
                if (!this.bold.IsNull && (font == null || this.Bold != font.Bold))
                {
                    serializer.WriteSimpleAttribute("Bold", this.Bold);
                }

                if (!this.italic.IsNull && (font == null || this.Italic != font.Italic))
                {
                    serializer.WriteSimpleAttribute("Italic", this.Italic);
                }

                if (!this.underline.IsNull && (font == null || this.Underline != font.Underline))
                {
                    serializer.WriteSimpleAttribute("Underline", this.Underline);
                }

                if (!this.superscript.IsNull && (font == null || this.Superscript != font.Superscript))
                {
                    serializer.WriteSimpleAttribute("Superscript", this.Superscript);
                }

                if (!this.subscript.IsNull && (font == null || this.Subscript != font.Subscript))
                {
                    serializer.WriteSimpleAttribute("Subscript", this.Subscript);
                }

                if (!this.color.IsNull && (font == null || this.Color.Argb != font.Color.Argb))// && this.Color.RGB != Color.Transparent.RGB)
                {
                    serializer.WriteSimpleAttribute("Color", this.Color);
                }
#endif
                serializer.EndContent(pos);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Converts Font into DDL. Properties with the same value as in an optionally given
        /// font are not serialized.
        /// </summary>
        internal void Serialize(Serializer serializer, Font font)
        {
            if (Parent is FormattedText)
            {
                string fontStyle = "";
                if (((FormattedText)Parent)._style.IsNull)
                {
                    // Check if we can use a DDL keyword.
                    FontProperties notNull = CheckWhatIsNotNull();
                    if (notNull == FontProperties.Size)
                    {
                        serializer.Write("\\fontsize(" + _size + ")");
                        return;
                    }
                    if (notNull == FontProperties.Bold && _bold.Value)
                    {
                        serializer.Write("\\bold");
                        return;
                    }
                    if (notNull == FontProperties.Italic && _italic.Value)
                    {
                        serializer.Write("\\italic");
                        return;
                    }
                    // SRG
                    //@{
                    if (notNull == FontProperties.Strikethrough && _strikethrough.Value)
                    {
                        serializer.Write("\\strikethrough");
                        return;
                    }
                    if (notNull == FontProperties.Rectangle)
                    {
                        serializer.Write("\\rectangle(" + _rectangle.ToString() + ")");
                        return;
                    }
                    //@}
                    if (notNull == FontProperties.Color)
                    {
                        serializer.Write("\\fontcolor(" + _color + ")");
                        return;
                    }
                }
                else
                {
                    fontStyle = "(\"" + ((FormattedText)Parent).Style + "\")";
                }

                //bool needBlank = false;  // nice, but later...
                serializer.Write("\\font" + fontStyle + "[");

                if (!_name.IsNull && _name.Value != "")
                {
                    serializer.WriteSimpleAttribute("Name", Name);
                }

#if DEBUG_ // Test
                if (!_size.IsNull && Size != 0 && Size.Point == 0)
                {
                    GetType();
                }
#endif
                if ((!_size.IsNull))
                {
                    serializer.WriteSimpleAttribute("Size", Size);
                }

                if (!_bold.IsNull)
                {
                    serializer.WriteSimpleAttribute("Bold", Bold);
                }

                if (!_italic.IsNull)
                {
                    serializer.WriteSimpleAttribute("Italic", Italic);
                }

                // SRG
                //@{
                if (!_strikethrough.IsNull)
                {
                    serializer.WriteSimpleAttribute("Strikethrough", Strikethrough);
                }
                if (!_rectangle.IsNull)
                {
                    serializer.WriteSimpleAttribute("Rectangle", Rectangle);
                }
                //@}

                if (!_underline.IsNull)
                {
                    serializer.WriteSimpleAttribute("Underline", Underline);
                }

                if (!_superscript.IsNull)
                {
                    serializer.WriteSimpleAttribute("Superscript", Superscript);
                }

                if (!_subscript.IsNull)
                {
                    serializer.WriteSimpleAttribute("Subscript", Subscript);
                }

                if (!_color.IsNull)
                {
                    serializer.WriteSimpleAttribute("Color", Color);
                }

                serializer.Write("]");
            }
            else
            {
                int pos = serializer.BeginContent("Font");

#if true
                // Don't write null values if font is null.
                // Do write null values if font is not null!
                if ((!_name.IsNull && Name != String.Empty && font == null) ||
                    (font != null && !_name.IsNull && Name != String.Empty && Name != font.Name))
                {
                    serializer.WriteSimpleAttribute("Name", Name);
                }

#if DEBUG_
                // Test
                if (!_size.IsNull && Size != 0 && Size.Point == 0)
                {
                    GetType();
                }
#endif

                if (!_size.IsNull &&
                    (font == null || Size != font.Size))
                {
                    serializer.WriteSimpleAttribute("Size", Size);
                }
                // NBool and NEnum have to be compared directly to check whether the value Null is.
                if (!_bold.IsNull && (font == null || Bold != font.Bold || font._bold.IsNull))
                {
                    serializer.WriteSimpleAttribute("Bold", Bold);
                }

                if (!_italic.IsNull && (font == null || Italic != font.Italic || font._italic.IsNull))
                {
                    serializer.WriteSimpleAttribute("Italic", Italic);
                }

                // SRG
                //@{
                if (!_strikethrough.IsNull && (font == null || Strikethrough != font.Strikethrough || font._strikethrough.IsNull))
                {
                    serializer.WriteSimpleAttribute("Strikethrough", Strikethrough);
                }
                if (!_rectangle.IsNull && (font == null || Rectangle != font.Rectangle || font._rectangle.IsNull))
                {
                    serializer.WriteSimpleAttribute("Rectangle", Rectangle);
                }
                //@}

                if (!_underline.IsNull && (font == null || Underline != font.Underline || font._underline.IsNull))
                {
                    serializer.WriteSimpleAttribute("Underline", Underline);
                }

                if (!_superscript.IsNull && (font == null || Superscript != font.Superscript || font._superscript.IsNull))
                {
                    serializer.WriteSimpleAttribute("Superscript", Superscript);
                }

                if (!_subscript.IsNull && (font == null || Subscript != font.Subscript || font._subscript.IsNull))
                {
                    serializer.WriteSimpleAttribute("Subscript", Subscript);
                }

                if (!_color.IsNull && (font == null || Color.Argb != font.Color.Argb))// && Color.RGB != Color.Transparent.RGB)
                {
                    serializer.WriteSimpleAttribute("Color", Color);
                }
#else
                if ((!this.name.IsNull && Name != String.Empty) && (font == null || Name != font.Name))
                {
                    serializer.WriteSimpleAttribute("Name", Name);
                }

                if (!this.size.IsNull && (font == null || Size != font.Size))
                {
                    serializer.WriteSimpleAttribute("Size", Size);
                }
                //NBool and NEnum have to be compared directly to check whether the value Null is
                if (!this.bold.IsNull && (font == null || Bold != font.Bold))
                {
                    serializer.WriteSimpleAttribute("Bold", Bold);
                }

                if (!this.italic.IsNull && (font == null || Italic != font.Italic))
                {
                    serializer.WriteSimpleAttribute("Italic", Italic);
                }

                if (!this.underline.IsNull && (font == null || Underline != font.Underline))
                {
                    serializer.WriteSimpleAttribute("Underline", Underline);
                }

                if (!this.superscript.IsNull && (font == null || Superscript != font.Superscript))
                {
                    serializer.WriteSimpleAttribute("Superscript", Superscript);
                }

                if (!this.subscript.IsNull && (font == null || Subscript != font.Subscript))
                {
                    serializer.WriteSimpleAttribute("Subscript", Subscript);
                }

                if (!this.color.IsNull && (font == null || Color.Argb != font.Color.Argb))// && Color.RGB != Color.Transparent.RGB)
                {
                    serializer.WriteSimpleAttribute("Color", Color);
                }
#endif
                serializer.EndContent(pos);
            }
        }
Ejemplo n.º 23
0
        private void ExecutedHandler(object sender, ExecutedRoutedEventArgs e)
        {
            // При любой команде мержинг отменяется, мало ли что там команда навыполняла
            PushUndoAction(null, false);

            RichTextBox edit = (RichTextBox)sender;

            if (e.Command == EditingCommands.DeletePreviousWord ||
                e.Command == EditingCommands.DeleteNextWord)
            {
                if (!edit.Selection.IsEmpty)
                {
                    RemoveSelection(edit);
                }
                else
                {
                    int         offsetFromEnd   = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition);
                    int         offsetFromStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition);
                    TextPointer pointer         = edit.CaretPosition;

                    if (e.Command == EditingCommands.DeletePreviousWord)
                    {
                        int resOffset = FindNextWhitespaceBackward(edit);

                        if (resOffset != -1)
                        {
                            TextRange range = new TextRange(
                                edit.Document.ContentStart.GetPositionAtOffset(resOffset),
                                edit.Document.ContentEnd.GetPositionAtOffset(offsetFromEnd));

                            PushUndoAction(new UndoBlockRemove(edit, range), true);
                            range.Text = "";
                        }
                    }
                    else if (e.Command == EditingCommands.DeleteNextWord)
                    {
                        int resOffset = FindNextWhitespaceForward(edit);

                        if (resOffset != -1)
                        {
                            TextRange range = new TextRange(
                                edit.Document.ContentStart.GetPositionAtOffset(resOffset),
                                edit.Document.ContentStart.GetPositionAtOffset(offsetFromStart));

                            PushUndoAction(new UndoBlockRemove(edit, range), true);
                            range.Text = "";
                        }
                    }
                }

                e.Handled = true;
                LinksCheck(CaretPosition);
            }

            if (e.Command == ApplicationCommands.Cut)
            {
                if (!edit.Selection.IsEmpty)
                {
                    edit.Copy();
                    RemoveSelection(this);
                    LinksCheck(CaretPosition);
                }

                e.Handled = true;
                return;
            }

            if (e.Command == ApplicationCommands.Paste)
            {
                if (!Clipboard.ContainsData(DataFormats.Rtf) && !Clipboard.ContainsData(DataFormats.Text))
                {
                    e.Handled = true;
                    return;
                }

                var undoGroup = new UndoGroup();

                // Удалить старое содержимое
                if (!edit.Selection.IsEmpty)
                {
                    FormatUndo undoFormat = new FormatUndo(edit.Document, edit.Selection, edit);
                    undoGroup.Add(undoFormat);
                    edit.Selection.Text = "";
                    undoFormat.UpdateSelectionOffsets(edit, edit.Selection);
                }

                int offsetStart = edit.Document.ContentStart.GetOffsetToPosition(edit.Selection.Start);
                int offsetEnd   = edit.Document.ContentEnd.GetOffsetToPosition(edit.Selection.End);
                var undoPaste   = new UndoPaste(edit, offsetStart, offsetEnd);

                bool wasError = false;
                if (Clipboard.ContainsData(DataFormats.Rtf))
                {
                    try
                    {
                        var rtfStream = MemoryStreamFromClipboard();
                        edit.Selection.Load(rtfStream, DataFormats.Rtf);
                    }
                    catch
                    {
                        wasError = true;
                    }
                }
                else if (Clipboard.ContainsData(DataFormats.Text))
                {
                    edit.Selection.Text = (string)Clipboard.GetData(DataFormats.Text);
                }

                // Если была ошибка добавления текста, то
                if (wasError == false)
                {
                    undoGroup.Add(undoPaste);
                    PushUndoAction(undoGroup, true);
                    edit.CaretPosition = edit.Selection.End;
                }

                // Проверить, все ли линки на месте
                LinksCheck(CaretPosition);

                // Обновить хендлеры у новых ссылок (которые могли прийти с клипбоардом)
                Links_Update();

                e.Handled = true;
                return;
            }

            if (e.Command == EditingCommands.AlignCenter ||
                e.Command == EditingCommands.AlignJustify ||
                e.Command == EditingCommands.AlignLeft ||
                e.Command == EditingCommands.AlignRight ||
                e.Command == EditingCommands.IncreaseIndentation ||
                e.Command == EditingCommands.TabBackward ||
                e.Command == EditingCommands.TabForward ||
                e.Command == EditingCommands.ToggleNumbering ||
                e.Command == EditingCommands.ToggleSubscript ||
                e.Command == EditingCommands.ToggleSuperscript)
            {
                e.Handled = true;
                return;
            }
            //e.Command == EditingCommands.ToggleUnderline

            if (e.Command == EditingCommands.IncreaseFontSize ||
                e.Command == EditingCommands.DecreaseFontSize ||
                e.Command == EditingCommands.ToggleBold ||
                e.Command == EditingCommands.ToggleItalic ||
                e.Command == EditingCommands.ToggleUnderline ||
                e.Command == OutlinerCommands.ToggleCrossed)
            {
                if (!edit.Selection.IsEmpty)
                {
                    var bu = new FormatUndo(edit.Document, edit.Selection, edit);
                    PushUndoAction(bu, true);

                    if (e.Command == EditingCommands.ToggleBold)
                    {
                        IsSelectionBold = !IsSelectionBold;
                    }
                    else if (e.Command == EditingCommands.ToggleItalic)
                    {
                        IsSelectionItalic = !IsSelectionItalic;
                    }
                    else if (e.Command == EditingCommands.ToggleUnderline)
                    {
                        IsSelectionUnderlined = !IsSelectionUnderlined;
                    }
                    else if (e.Command == OutlinerCommands.ToggleCrossed)
                    {
                        IsSelectionStrikethrough = !IsSelectionStrikethrough;
                    }

                    /*if (e.Command == OutlinerCommands.ToggleCrossed)
                     *  IsSelectionStrikethrough = !IsSelectionStrikethrough;*/

                    bu.UpdateSelectionOffsets(edit, edit.Selection);
                    e.Handled = true;
                }
                else
                {
                    TextRange paragraphRange;
                    if (edit.CaretPosition.Paragraph != null)
                    {
                        paragraphRange = new TextRange(edit.CaretPosition.Paragraph.ContentStart,
                                                       edit.CaretPosition.Paragraph.ContentEnd);
                    }
                    else
                    {
                        paragraphRange = new TextRange(edit.Document.ContentStart,
                                                       edit.Document.ContentEnd);
                    }

                    FontProperties fontProps = new FontProperties(paragraphRange);
                    var            bu        = new FormatUndo(edit.Document,
                                                              paragraphRange,
                                                              edit);


                    int caretPositionStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition);
                    int caretPositionEnd   = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition);

                    if (e.Command == EditingCommands.ToggleBold)
                    {
                        IsSelectionBold = !IsSelectionBold;
                    }
                    else if (e.Command == EditingCommands.ToggleItalic)
                    {
                        IsSelectionItalic = !IsSelectionItalic;
                    }
                    else if (e.Command == EditingCommands.ToggleUnderline)
                    {
                        IsSelectionUnderlined = !IsSelectionUnderlined;
                    }
                    else if (e.Command == OutlinerCommands.ToggleCrossed)
                    {
                        IsSelectionStrikethrough = !IsSelectionStrikethrough;
                    }

                    int newCaretPositionStart = edit.Document.ContentStart.GetOffsetToPosition(edit.CaretPosition);
                    int newCaretPositionEnd   = edit.Document.ContentEnd.GetOffsetToPosition(edit.CaretPosition);

                    string paragraphRangeText = paragraphRange.Text;
                    if (caretPositionStart != newCaretPositionStart || caretPositionEnd != newCaretPositionEnd ||
                        !fontProps.HasSameStyle(paragraphRange))
                    {
                        PushUndoAction(bu, true);
                    }

                    e.Handled = true;
                }
                return;
            }

            if (e.Command == EditingCommands.Backspace ||
                e.Command == EditingCommands.Delete)
            {
                if (!edit.Selection.IsEmpty)
                {
                    RemoveSelection(edit);
                    LinksCheck(CaretPosition);
                    e.Handled = true;
                }
                else
                {
                    TextPointer right = edit.Selection.Start;
                    TextPointer left  = right.GetNextInsertionPosition(LogicalDirection.Backward);

                    if (e.Command == EditingCommands.Delete)
                    {
                        left  = edit.Selection.Start;
                        right = right.GetNextInsertionPosition(LogicalDirection.Forward);
                    }

                    if (right != null && left != null)
                    {
                        TextRange range = new TextRange(right, left);
                        if (range.Text != "")
                        {
                            var bu = new UndoBlockRemove(edit, range);
                            PushUndoAction(bu, true);

                            range.ClearAllProperties();
                            range.Text = "";

                            bu.UpdateOffsets(edit, range);
                        }
                    }

                    LinksCheck(CaretPosition);
                    e.Handled = true;
                }
            }
        }
Ejemplo n.º 24
0
 public virtual void AcceptMetafileDescriptorFontProperties(FontProperties fontProperties, T parameter)
 {
     // intentionally left blank
 }
Ejemplo n.º 25
0
 public Class33(FontProperties properties)
 {
     this.fontProperties_0 = properties;
     this.method_0();
 }
Ejemplo n.º 26
0
 public Class29(FontProperties properties, FontType fontType)
 {
     this.fontProperties_0 = properties;
     this.fontType_0       = fontType;
 }
Ejemplo n.º 27
0
		public static void SetHtml(this TextBlock textBlock, string text)
		{
			// Constants
			try
			{
				FontProperties item = new FontProperties();
				item.face = textBlock.FontFamily.Source;
				item.size = textBlock.FontSize;
				item.brush = textBlock.Foreground;
				item.bold = false;
				item.italic = false;
				item.underline = false;
				item.listitem = false;
				item.listtype = 0;
				item.listitems = 0;
				item.indent = 0;
				item.link = null;
				g_sFonts = new Stack<FontProperties>();
				g_sFonts.Push(item);
				g_iPrevLineBreaks = 2;

				if (textBlock.Inlines == null)
					textBlock.Text = ""; // TextBlock Bug: work around the null inlines

				// Clear the collection of Inlines
				textBlock.Inlines.Clear();

				// Wrap the input in a <DIV> (so even plain text becomes valid XML)
				StringReader stringReader = new StringReader(string.Concat("<DIV>", text, "</DIV>"));

				// Read the input
				XmlReader xmlReader = XmlReader.Create(stringReader);

				// Read the entire XML DOM...
				while (xmlReader.Read())
				{
					string nameLower = xmlReader.Name.ToLower();
					if (xmlReader.NodeType == XmlNodeType.Element)
					{
						bool bEmpty = xmlReader.IsEmptyElement;

						// Handle the begin element
						switch (nameLower)
						{
							case "a":
							{
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								if (xmlReader.MoveToFirstAttribute())
								do
								{
									if (xmlReader.Name.ToLower() == "href")
									{
										font.link = xmlReader.Value;
										font.underline = true;
										font.brush = Colors.Blue.ToBrush();
									}
								}
								while (xmlReader.MoveToNextAttribute());
								g_sFonts.Push(font);
								break;
							}

							case "font":
							{
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								if (xmlReader.MoveToFirstAttribute())
								do
								{
									if (xmlReader.Name.ToLower() == "face")
										font.face = xmlReader.Value;
									if (xmlReader.Name.ToLower() == "size")
										font.size = Convert.ToDouble(xmlReader.Value);
									if (xmlReader.Name.ToLower() == "color")
										font.brush = xmlReader.Value.ToColor().ToBrush();
								}
								while (xmlReader.MoveToNextAttribute());
								g_sFonts.Push(font);
								break;
							}
							
							case "b":
							case "strong":
							{
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								font.bold = true;
								g_sFonts.Push(font);
								break;
							}

							case "h1":
							case "h2":
							case "h3":
							case "h4":
							case "h5":
							case "h6":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();

								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								if (nameLower == "h1") font.size *= (24.0/12);	// xx-large	24pt	32pix
								if (nameLower == "h2") font.size *= (18.0/12);	// x-large	18pt	24pix
								if (nameLower == "h3") font.size *= (13.5/12);	// large	13.5pt	18pix
								if (nameLower == "h4") font.size *= (12.0/12);	// medium	12pt	16pix
								if (nameLower == "h5") font.size *= (10.5/12);	// sSmall	10.5pt	14pix
								if (nameLower == "h6") font.size *= ( 7.5/12);	// x-small	7.5pt	10pix
																				// xx-small	7.5pt	10pix
								font.bold = true;
								g_sFonts.Push(font);
								break;
							}

							case "i":
							case "em":
							case "cite":
							{
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								font.italic = true;
								g_sFonts.Push(font);
								break;
							}

							case "u":
							{
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								font.underline = true;
								g_sFonts.Push(font);
								break;
							}

							case "br":
							{
								textBlock.InlinesAdd(new LineBreak());
								break;
							}

							case "pre":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();

								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Peek();
								font.face = "Courier New";
								g_sFonts.Push(font);
								break;
							}

							case "p":
							case "form":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();
								break;
							}

							case "ol":
							case "ul":
							case "dir":
							case "menu":
							{
								textBlock.BreakAfterText();

								FontProperties font = g_sFonts.Peek();
								if (bEmpty || font.listtype == 0)
									textBlock.StartNewParagraph();

								if (bEmpty)
									break;

								font.listtype = (nameLower == "ol" ? 1 : 2);
								font.listitems = 0;
								font.indent += 3;
								g_sFonts.Push(font);
								break;
							}

							case "li":
							{
								textBlock.BreakAfterText();
								if (bEmpty)
									break;

								FontProperties font = g_sFonts.Pop(); // Pop not Peek here
								font.listitems++;
								g_sFonts.Push(font);
								font.listitem = true;
								g_sFonts.Push(font);
								break;
							}

							case "div":
							case "center":
							{
								textBlock.BreakAfterText();
								break;
							}

							case "span":
							{
								break;
							}
						}
					}
					else
					if (xmlReader.NodeType == XmlNodeType.EndElement)
					{
						// Handle the end element
						switch (nameLower)
						{
							case "a":
							{
								g_sFonts.Pop();
								break;
							}

							case "font":
							{
								g_sFonts.Pop();
								break;
							}

							case "b":
							case "strong":
							{
								g_sFonts.Pop();
								break;
							}

							case "h1":
							case "h2":
							case "h3":
							case "h4":
							case "h5":
							case "h6":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();
								g_sFonts.Pop();
								break;
							}

							case "i":
							case "em":
							case "cite":
							{
								g_sFonts.Pop();
								break;
							}

							case "u":
							{
								g_sFonts.Pop();
								break;
							}

							case "br":
							{
								break;
							}

							case "pre":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();
								g_sFonts.Pop();
								break;
							}

							case "p":
							case "form":
							{
								textBlock.BreakAfterText();
								textBlock.StartNewParagraph();
								break;
							}

							case "ol":
							case "ul":
							case "dir":
							case "menu":
							{
								textBlock.BreakAfterText();

								FontProperties font = g_sFonts.Pop();
								if (font.listtype == 0)
									textBlock.StartNewParagraph();

								break;
							}

							case "li":
							{
								textBlock.BreakAfterText();
								g_sFonts.Pop();
								break;
							}

							case "div":
							case "center":
							{
								textBlock.BreakAfterText();
								break;
							}

							case "span":
							{
								break;
							}
						}
					}
					else
					if (xmlReader.NodeType == XmlNodeType.Text)
					{
						// Create a Run for the visible text
						// Collapse contiguous whitespace per HTML behavior
						StringBuilder builder = new StringBuilder(xmlReader.Value.Length);
						char cLast = (g_iPrevLineBreaks > 0 ? ' ' : '\0');
						foreach (char ch in xmlReader.Value)
						{
							char c = ch;
							if (c == '\t' || c == '\n') c = ' ';
							bool bSkip = (cLast == ' ' && c == ' ');
							cLast = c;
							if (!bSkip)
								builder.Append(c);
						}

						// If any text to display...
						string builderString = builder.ToString();
						if (builderString.Length > 0)
						{
							// Create a Run to display it
							Run run = new Run();
							run.Text = builderString;
							textBlock.InlinesAdd(run);
						}
					}
					else
					if (xmlReader.NodeType == XmlNodeType.Whitespace)
					{
					}
				}
			}
			catch (Exception e)
			{
				System.Diagnostics.Debug.WriteLine(e.Message);
				e.Assert();

				// Invalid XHTML
				textBlock.Inlines.Clear();
				textBlock.Text = text;
			}
		}
Ejemplo n.º 28
0
 /// <summary>
 /// Directly render text to the screen.
 /// </summary>
 /// <param name="spriteFont"></param>
 /// <param name="text"></param>
 /// <param name="position"></param>
 /// <param name="properties"></param>
 public void RenderText(SpriteFont spriteFont, StringBuilder text, Vector2 position, FontProperties properties)
 {
     RenderText(spriteFont
                , text
                , position
                , properties.Tint
                , properties.Rotation
                , properties.Origin
                , properties.Scale
                , properties.SpriteEffects
                , originIsRelative: properties.OriginIsRelative);
 }
Ejemplo n.º 29
0
 public Class32(FontProperties properties)
     : base(properties)
 {
     this.method_3();
     this.string_2 = new Random().Next(1048576, 16777215).ToString("X").Substring(0, 6);
 }