예제 #1
0
 public static Label TextDecorations(this Label label, TextDecorations decorations)
 {
     label.TextDecorations = decorations;
     return(label);
 }
예제 #2
0
        public static FontStyle GetStyleFontStyle(FontStyles style, FontWeights weight, TextDecorations textDecoration)
        {
            FontStyle fontStyle = FontStyle.Regular;

            if (style == FontStyles.Italic)
            {
                fontStyle = FontStyle.Italic;
            }
            switch (weight)
            {
            case FontWeights.SemiBold:
            case FontWeights.Bold:
            case FontWeights.ExtraBold:
            case FontWeights.Heavy:
                fontStyle |= FontStyle.Bold;
                break;
            }
            switch (textDecoration)
            {
            case TextDecorations.LineThrough:
                fontStyle |= FontStyle.Strikeout;
                break;

            case TextDecorations.Underline:
                fontStyle |= FontStyle.Underline;
                break;
            }
            return(fontStyle);
        }
예제 #3
0
        public void TestTextDecorationConverter(string input, TextDecorations expected)
        {
            var converter = new TextDecorationConverter();

            Assert.AreEqual(converter.ConvertFromInvariantString(input), expected);
        }
예제 #4
0
        /// <summary>
        /// Builds a TextPaint configuration.
        /// </summary>
        /// <remarks>
        /// This is required for some JNI related reason.
        /// At some point, the reference to a member field TextPaint gets collected if used
        /// in some of the StaticLayout methods, so we create a local copy of the
        /// paint to be used in this context.
        /// One solution could be to use a <see cref="Android.Runtime.JNIEnv.NewGlobalRef"/>, but the release of the reference
        /// can be tricky to place properly.
        /// </remarks>
        /// <returns>A <see cref="TextPaint"/> instance.</returns>
        public static TextPaint GetPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
        {
            if (shader != null)
            {
                // The "Shader" native object can't be use as a cache key
                return(InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations));
            }

            var key = new Entry(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, baselineAlignment, textDecorations);

            if (!_entries.TryGetValue(key, out var paint))
            {
                _entries.Add(key, paint = InnerBuildPaint(fontWeight, fontStyle, fontFamily, fontSize, characterSpacing, foreground, shader, baselineAlignment, textDecorations));
            }

            return(paint);
        }
예제 #5
0
 public static Span TextDecorations(this Span span, TextDecorations decorations)
 {
     span.TextDecorations = decorations;
     return(span);
 }
예제 #6
0
        private static TextPaint InnerBuildPaint(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Color foreground, Shader shader, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
        {
            var paint = new TextPaint(PaintFlags.AntiAlias);

            var paintSpecs = BuildPaintValueSpecs(fontSize, characterSpacing);

            paint.Density        = paintSpecs.density;
            paint.TextSize       = paintSpecs.textSize;
            paint.UnderlineText  = (textDecorations & TextDecorations.Underline) == TextDecorations.Underline;
            paint.StrikeThruText = (textDecorations & TextDecorations.Strikethrough) == TextDecorations.Strikethrough;
            if (shader != null)
            {
                paint.SetShader(shader);
            }

            if (baselineAlignment == BaseLineAlignment.Superscript)
            {
                paint.BaselineShift += (int)(paint.Ascent() / 2);
            }

            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
            {
                paint.LetterSpacing = paintSpecs.letterSpacing;
            }
            else
            {
                LogCharacterSpacingNotSupported();
            }

            var typefaceStyle = TypefaceStyleHelper.GetTypefaceStyle(fontStyle, fontWeight);
            var typeface      = FontHelper.FontFamilyToTypeFace(fontFamily, fontWeight, typefaceStyle);

            paint.SetTypeface(typeface);
            paint.Color = foreground;

            return(paint);
        }
예제 #7
0
 public Entry(FontWeight fontWeight, FontStyle fontStyle, FontFamily fontFamily, double fontSize, double characterSpacing, Windows.UI.Color foreground, BaseLineAlignment baselineAlignment, TextDecorations textDecorations)
 {
     FontWeight        = fontWeight;
     FontStyle         = fontStyle;
     FontFamily        = fontFamily;
     FontSize          = fontSize;
     CharacterSpacing  = characterSpacing;
     Foreground        = foreground;
     BaseLineAlignment = baselineAlignment;
     TextDecorations   = textDecorations;
 }
예제 #8
0
        public static IntPtr Box_TextDecorations(TextDecorations val)
        {
            IntPtr ret = NoesisGUI_PINVOKE.Box_TextDecorations((int)val);

            return(ret);
        }
예제 #9
0
        public static TextDecorations Unbox_TextDecorations(IntPtr val)
        {
            TextDecorations ret = (TextDecorations)NoesisGUI_PINVOKE.Unbox_TextDecorations(val);

            return(ret);
        }
예제 #10
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                FontChooserDialogView dialog = new FontChooserDialogView();
                dialog.SelectedFamily   = TextFormat.FontFamily;
                dialog.SelectedTypeface = new Typeface(TextFormat.FontFamily, TextFormat.FontStyle, TextFormat.FontWeight, FontStretches.Normal);
                dialog.SelectedSize     = TextFormat.FontSize;

                if (TextFormat.Decorations.HasFlag(TextDecorations.Underline))
                {
                    dialog.IsUnderline = true;
                }
                if (TextFormat.Decorations.HasFlag(TextDecorations.Strikethrough))
                {
                    dialog.IsStrikethrough = true;
                }
                if (TextFormat.Decorations.HasFlag(TextDecorations.Baseline))
                {
                    dialog.IsBaseline = true;
                }
                if (TextFormat.Decorations.HasFlag(TextDecorations.Overline))
                {
                    dialog.IsOverLine = true;
                }


                dialog.Owner = Window.GetWindow(this);
                Nullable <bool> results = dialog.ShowDialog();
                if (results != null && results == true)
                {
                    //ConfigManager.UndoManager.StartBatch();
                    TextFormat.FontFamily = dialog.SelectedTypeface.FontFamily;
                    TextFormat.FontStyle  = dialog.SelectedTypeface.Style;
                    TextFormat.FontWeight = dialog.SelectedTypeface.Weight;
                    TextFormat.FontSize   = dialog.SelectedSize;

                    TextDecorations newDecorations = 0;
                    if (dialog.IsUnderline)
                    {
                        newDecorations |= TextDecorations.Underline;
                    }
                    if (dialog.IsStrikethrough)
                    {
                        newDecorations |= TextDecorations.Strikethrough;
                    }
                    if (dialog.IsBaseline)
                    {
                        newDecorations |= TextDecorations.Baseline;
                    }
                    if (dialog.IsOverLine)
                    {
                        newDecorations |= TextDecorations.Overline;
                    }
                    TextFormat.Decorations = newDecorations;

                    //ConfigManager.UndoManager.CloseBatch();
                }
            }
            catch (Exception re)
            {
                //ConfigManager.LogManager.LogError("Error opening text format editor.", re);
            }
        }
예제 #11
0
        public async Task TextDecorationsDoesNotAffectHorizontalTextAlignment(TextDecorations initialDecorations, TextDecorations newDecorations)
        {
            var label = new LabelStub
            {
                Text = "This is TEXT!",
                HorizontalTextAlignment = TextAlignment.Center,
                TextDecorations         = initialDecorations,
            };

            await ValidateUnrelatedPropertyUnaffected(
                label,
                GetNativeHorizontalTextAlignment,
                nameof(ILabel.TextDecorations),
                () => label.TextDecorations = newDecorations);
        }
예제 #12
0
        public static NSMutableAttributedString?WithDecorations(this NSAttributedString attributedString, TextDecorations decorations)
        {
            if (attributedString == null || attributedString.Length == 0)
            {
                return(null);
            }

            var mutable = new NSMutableAttributedString(attributedString);

            var range = new NSRange(0, mutable.Length);

            UpdateDecoration(mutable, UIStringAttributeKey.StrikethroughStyle, range,
                             decorations & TextDecorations.Strikethrough);

            UpdateDecoration(mutable, UIStringAttributeKey.UnderlineStyle, range,
                             decorations & TextDecorations.Underline);

            return(mutable);
        }