示例#1
0
        /// <summary>
        /// Returns a list of Typographic Variants for a character supported by the font.
        /// </summary>
        public static List <TypographyFeatureInfo> GetCharacterVariants(FontVariant font, Models.Character character)
        {
            var textAnalyzer = new CanvasTextAnalyzer(character.Char, CanvasTextDirection.TopToBottomThenLeftToRight);
            KeyValuePair <CanvasCharacterRange, CanvasAnalyzedScript> analyzed = textAnalyzer.GetScript().First();

            List <TypographyFeatureInfo> supported = new List <TypographyFeatureInfo>
            {
                TypographyFeatureInfo.None
            };

            foreach (var feature in font.XamlTypographyFeatures)
            {
                if (feature == TypographyFeatureInfo.None)
                {
                    continue;
                }

                var    glyphs  = textAnalyzer.GetGlyphs(analyzed.Key, font.FontFace, 24, false, false, analyzed.Value);
                bool[] results = font.FontFace.GetTypographicFeatureGlyphSupport(analyzed.Value, feature.Feature, glyphs);

                if (results.Any(r => r))
                {
                    supported.Add(feature);
                }
            }

            return(supported);
        }
        public TypographyHandler(string text)
        {
            var textAnalyzer = new CanvasTextAnalyzer(text, CanvasTextDirection.TopToBottomThenLeftToRight);

            _analyzedScript = textAnalyzer.GetScript();

            TypographyOptions = new List <TypographyFeatureInfo>
            {
                new TypographyFeatureInfo(CanvasTypographyFeatureName.None)
            };
        }
            public TypographyHandler(string text)
            {
                var textAnalyzer = new CanvasTextAnalyzer(text, CanvasTextDirection.TopToBottomThenLeftToRight);
                analyzedScript = textAnalyzer.GetScript();

                TypographyOptions = new List<TypographyFeatureInfo>();
                TypographyOptions.Add(new TypographyFeatureInfo(CanvasTypographyFeatureName.None));

                CurrentMode = Mode.BuildTypographyList;
                FeatureToHighlight = CanvasTypographyFeatureName.None;
            }
            public TypographyHandler(string text)
            {
                var textAnalyzer = new CanvasTextAnalyzer(text, CanvasTextDirection.TopToBottomThenLeftToRight);

                analyzedScript = textAnalyzer.GetScript();

                TypographyOptions = new List <TypographyFeatureInfo>();
                TypographyOptions.Add(new TypographyFeatureInfo(CanvasTypographyFeatureName.None));

                CurrentMode        = Mode.BuildTypographyList;
                FeatureToHighlight = CanvasTypographyFeatureName.None;
            }
示例#5
0
        public static List <TypographyFeatureInfo> GetSupportedTypographyFeatures(FontVariant variant)
        {
            Dictionary <string, TypographyFeatureInfo> features = new Dictionary <string, TypographyFeatureInfo>();
            var analyzer = new CanvasTextAnalyzer(variant.GetCharString(), CanvasTextDirection.LeftToRightThenTopToBottom);

            {
                foreach (var script in analyzer.GetScript())
                {
                    foreach (var feature in variant.FontFace.GetSupportedTypographicFeatureNames(script.Value))
                    {
                        var info = new TypographyFeatureInfo(feature);
                        if (!features.ContainsKey(info.DisplayName))
                        {
                            features.Add(info.DisplayName, info);
                        }
                    }
                }
            }

            return(features.Values.OrderBy(f => f.DisplayName).ToList());
        }
示例#6
0
        private void EnsureLayout(CanvasControl sender)
        {
            if (!needsLayout)
            {
                return;
            }

            var geometry = GetLayoutGeometry(sender);

            string text;

            if (CurrentTextOption == TextOption.English)
            {
                text =
                    "Win2D is an easy-to-use Windows Runtime API for immediate mode 2D graphics rendering with GPU acceleration. " +
                    "It is available to C# and C++ developers writing Windows apps for Windows 8.1, Windows Phone 8.1 and Windows " +
                    "10. It utilizes the power of Direct2D, and integrates seamlessly with XAML and CoreWindow. The CanvasTextAnalyzer " +
                    "class identifies what glyphs are needed to render a piece of text, including the font fallbacks to properly " +
                    "handle different languages.  Example Gallery uses it to create this Custom Text Layouts example, which wordwraps text " +
                    "to fill an arbitrary geometric shape.";
            }
            else
            {
                //
                // Storing bi-directional text as a contiguous literal causes problems in VS; it will attempt to reorder the bi-di levels
                // in the script, and it reorders them wrongly (doesn't match Word, Outlook, other programs). This works around it
                // by separating some of them out.
                //
                // This text string contains control characters around 'C#' and C++' to ensure they are drawn with the correct
                // directionality. Higher-level editors like Word use this same mechanism, since a full, correct Bidi ordering
                // isn't sufficient for them.
                //
                text =
                    "Win2D هو API  لنظام التشغيل ويندوز سهل الاستخدام لتقديم الرسومات الثنائية الابعاد " + "(2D)" +
                    "مع تسارع المعالج الجرافيك. متاح للمطورين \u202aC#\u202c و \u202aC+ +\u202c لتطوير تطبيقات الويندوز لإصدارات " +
                    "8.1،   10 و هاتف الويندوز إصدار 8.1. فإنه يستخدم قوة Direct2D، ويدمج بسهولة مع XAML وCoreWindows ." +
                    "الفئة CanvasTextAnalyzer يحدد ما هي الرموز المطلوبة لتقديم قطعة من " +
                    "النص، بما في ذلك أساسات الخط إلى التعامل مع لغات مختلفة. Example Gallery يستخدم هذه الطقنيه لعرض كيفية التعامل مع النصوص.";
            }

            // Duplicate the text, so that it fills more reading space.
            text = text + text;

            var textFormat = new CanvasTextFormat();

            textFormat.FontFamily = fontPicker.CurrentFontFamily;

            var textDirection = CurrentTextDirection == TextDirection.LeftToRight ?
                                CanvasTextDirection.LeftToRightThenTopToBottom : CanvasTextDirection.RightToLeftThenTopToBottom;

            CanvasTextAnalyzer textAnalyzer = new CanvasTextAnalyzer(text, textDirection);

            //
            // Figure out what fonts to use.
            //
            var fontResult = textAnalyzer.GetFonts(textFormat);

            //
            // Perform a script analysis on the text.
            //
            var scriptAnalysis = textAnalyzer.GetScript();

            //
            // Perform bidi analysis.
            //
            var bidiAnalysis = textAnalyzer.GetBidi();

            float maxLineSpacing = 0;
            List <FormattingSpan> formattingSpans = EvaluateFormattingSpans(textAnalyzer, fontResult, scriptAnalysis, bidiAnalysis, out maxLineSpacing);

            //
            // Perform line break analysis.
            //
            var breakpoints = textAnalyzer.GetBreakpoints();

            //
            // Get the rectangles to layout text into.
            //
            layoutRectangles = SplitGeometryIntoRectangles(geometry, maxLineSpacing, sender);

            //
            // Insert glyph runs into the layout boxes.
            //
            layoutBoxes = CreateGlyphRuns(layoutRectangles, formattingSpans, breakpoints);

            if (ShouldJustify)
            {
                Justify(textAnalyzer, layoutBoxes);
            }

            needsLayout = false;
        }