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; }
bool IsNamedFeature(CanvasTypographyFeatureName name) { // // DWrite and Win2D support a pre-defined list of typographic features. // However, fonts are free to expose features outside of that list. // In fact, many built-in fonts have such custom features. // // These custom features are also accessible through Win2D, and // are reported by GetSupportedTypographicFeatureNames. // return(_allValues.Contains(name)); }
public TypographyFeatureInfo(CanvasTypographyFeatureName n) { Feature = n; if (IsNamedFeature(Feature)) { DisplayName = Feature.Humanize().Transform(To.TitleCase); } else { // // For custom font features, we can produce the OpenType feature tag // using the feature name. // uint id = (uint)(Feature); DisplayName = DirectWrite.GetTagName(id); } }
bool IsNamedFeature(CanvasTypographyFeatureName name) { // // DWrite and Win2D support a pre-defined list of typographic features. // However, fonts are free to expose features outside of that list. // In fact, many built-in fonts have such custom features. // // These custom features are also accessible through Win2D, and // are reported by GetSupportedTypographicFeatureNames. // var allValues = Enum.GetValues(typeof(CanvasTypographyFeatureName)); foreach (var value in allValues) { if ((CanvasTypographyFeatureName)(value) == name) { return(true); } } return(false); }
public TypographyFeatureInfo(CanvasTypographyFeatureName n) { name = n; if (IsNamedFeature(name)) { stringName = name.ToString(); } else { // // For custom font features, we can produce the OpenType feature tag // using the feature name. // uint id = (uint)(name); stringName = ((char)((id >> 24) & 0xFF)).ToString() + ((char)((id >> 16) & 0xFF)).ToString() + ((char)((id >> 8) & 0xFF)).ToString() + ((char)((id >> 0) & 0xFF)).ToString() + " (Custom)"; } }
public TypographyFeatureInfo(CanvasTypographyFeatureName n, string displayName = null) { Feature = n; if (displayName != null) { DisplayName = displayName; } else if (IsNamedFeature(Feature)) { DisplayName = Feature.Humanise(); } else { // // For custom font features, we can produce the OpenType feature tag // using the feature name. // uint id = (uint)(Feature); DisplayName = DirectWrite.GetTagName(id); } }
public TypographyFeatureInfo(CanvasTypographyFeatureName n) { Feature = n; if (IsNamedFeature(Feature)) { DisplayName = Feature.Humanize().Transform(To.TitleCase); } else { // // For custom font features, we can produce the OpenType feature tag // using the feature name. // uint id = (uint)(Feature); DisplayName = ("Custom: ") + ((char)((id >> 24) & 0xFF)) + ((char)((id >> 16) & 0xFF)) + ((char)((id >> 8) & 0xFF)) + ((char)((id >> 0) & 0xFF)); } }
public static void SetTypography(IXamlDirectObject o, CanvasTypographyFeatureName f, XamlDirect _xamlDirect) { /* XAML Direct Helpers. Using XD is faster than setting Dependency Properties */ void Set(XamlPropertyIndex index, bool value) { _xamlDirect.SetBooleanProperty(o, index, value); } void SetE(XamlPropertyIndex index, uint e) { _xamlDirect.SetEnumProperty(o, index, e); } void SetI(XamlPropertyIndex index, bool val) { _xamlDirect.SetInt32Property(o, index, val ? 1 : 0); } /* TODO : ADD EASTASIAN TYPOGRAPY PROPERTIES */ /* Set CAPTIAL SPACING */ /* As Capital Spacing affects character spacing, it has no use when displaying single glyphs */ //Set(XamlPropertyIndex.Typography_CapitalSpacing, f == CanvasTypographyFeatureName.CapitalSpacing); /* Set KERNING */ /* As Kerning affects character spacing, it has no use when displaying single glyphs */ //Set(XamlPropertyIndex.Typography_Kerning, f == CanvasTypographyFeatureName.Kerning); /* Set SWASHES */ SetI(XamlPropertyIndex.Typography_StandardSwashes, f == CanvasTypographyFeatureName.Swash); SetI(XamlPropertyIndex.Typography_ContextualSwashes, f == CanvasTypographyFeatureName.ContextualSwash); /* Set ALTERNATES */ SetI(XamlPropertyIndex.Typography_AnnotationAlternates, f == CanvasTypographyFeatureName.AlternateAnnotationForms); SetI(XamlPropertyIndex.Typography_StylisticAlternates, f == CanvasTypographyFeatureName.StylisticAlternates); /* Contextual Alternates applies to combinations of characters, and as such has no purpose here yet */ Set(XamlPropertyIndex.Typography_ContextualAlternates, f == CanvasTypographyFeatureName.ContextualAlternates); /* Set MATHEMATICAL GREEK */ Set(XamlPropertyIndex.Typography_MathematicalGreek, f == CanvasTypographyFeatureName.MathematicalGreek); /* Set FORMS */ Set(XamlPropertyIndex.Typography_HistoricalForms, f == CanvasTypographyFeatureName.HistoricalForms); Set(XamlPropertyIndex.Typography_CaseSensitiveForms, f == CanvasTypographyFeatureName.CaseSensitiveForms); Set(XamlPropertyIndex.Typography_EastAsianExpertForms, f == CanvasTypographyFeatureName.ExpertForms); /* Set SLASHED ZERO */ Set(XamlPropertyIndex.Typography_SlashedZero, f == CanvasTypographyFeatureName.SlashedZero); /* Set LIGATURES */ /* Ligatures only apply to combinations of characters, and as such have no purpose here yet */ // Set(XamlPropertyIndex.Typography_StandardLigatures, f == CanvasTypographyFeatureName.StandardLigatures); // Set(XamlPropertyIndex.Typography_ContextualLigatures, f == CanvasTypographyFeatureName.ContextualLigatures); // Set(XamlPropertyIndex.Typography_HistoricalLigatures, f == CanvasTypographyFeatureName.HistoricalLigatures); // Set(XamlPropertyIndex.Typography_DiscretionaryLigatures, f == CanvasTypographyFeatureName.DiscretionaryLigatures); /* Set CAPITALS */ if (f == CanvasTypographyFeatureName.SmallCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.SmallCaps); } else if (f == CanvasTypographyFeatureName.SmallCapitalsFromCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.AllSmallCaps); } else if (f == CanvasTypographyFeatureName.PetiteCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.PetiteCaps); } else if (f == CanvasTypographyFeatureName.PetiteCapitalsFromCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.AllPetiteCaps); } else if (f == CanvasTypographyFeatureName.Titling) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Titling); } else if (f == CanvasTypographyFeatureName.Unicase) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Unicase); } else { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Normal); } /* Set NUMERAL ALIGNMENT */ /* Numeral Alignment only apply to combinations of characters, and as such have no purpose here yet */ //if (f == CanvasTypographyFeatureName.ProportionalFigures) // SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Proportional); //else if (f == CanvasTypographyFeatureName.TabularFigures) // SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Tabular); //else SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Normal); /* Set NUMERAL STYLE */ if (f == CanvasTypographyFeatureName.OldStyleFigures) { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.OldStyle); } else if (f == CanvasTypographyFeatureName.LiningFigures) { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.Lining); } else { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.Normal); } /* Set VARIANTS */ if (f == CanvasTypographyFeatureName.Ordinals) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Ordinal); } else if (f == CanvasTypographyFeatureName.Superscript) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Superscript); } else if (f == CanvasTypographyFeatureName.Subscript) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Subscript); } else if (f == CanvasTypographyFeatureName.RubyNotationForms) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Ruby); } else if (f == CanvasTypographyFeatureName.ScientificInferiors) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Inferior); } else { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Normal); } /* Set STLYISTIC SETS */ Set(XamlPropertyIndex.Typography_StylisticSet1, f == CanvasTypographyFeatureName.StylisticSet1); Set(XamlPropertyIndex.Typography_StylisticSet2, f == CanvasTypographyFeatureName.StylisticSet2); Set(XamlPropertyIndex.Typography_StylisticSet3, f == CanvasTypographyFeatureName.StylisticSet3); Set(XamlPropertyIndex.Typography_StylisticSet4, f == CanvasTypographyFeatureName.StylisticSet4); Set(XamlPropertyIndex.Typography_StylisticSet5, f == CanvasTypographyFeatureName.StylisticSet5); Set(XamlPropertyIndex.Typography_StylisticSet6, f == CanvasTypographyFeatureName.StylisticSet6); Set(XamlPropertyIndex.Typography_StylisticSet7, f == CanvasTypographyFeatureName.StylisticSet7); Set(XamlPropertyIndex.Typography_StylisticSet8, f == CanvasTypographyFeatureName.StylisticSet8); Set(XamlPropertyIndex.Typography_StylisticSet9, f == CanvasTypographyFeatureName.StylisticSet9); Set(XamlPropertyIndex.Typography_StylisticSet10, f == CanvasTypographyFeatureName.StylisticSet10); Set(XamlPropertyIndex.Typography_StylisticSet11, f == CanvasTypographyFeatureName.StylisticSet11); Set(XamlPropertyIndex.Typography_StylisticSet12, f == CanvasTypographyFeatureName.StylisticSet12); Set(XamlPropertyIndex.Typography_StylisticSet13, f == CanvasTypographyFeatureName.StylisticSet13); Set(XamlPropertyIndex.Typography_StylisticSet14, f == CanvasTypographyFeatureName.StylisticSet14); Set(XamlPropertyIndex.Typography_StylisticSet15, f == CanvasTypographyFeatureName.StylisticSet15); Set(XamlPropertyIndex.Typography_StylisticSet16, f == CanvasTypographyFeatureName.StylisticSet16); Set(XamlPropertyIndex.Typography_StylisticSet17, f == CanvasTypographyFeatureName.StylisticSet17); Set(XamlPropertyIndex.Typography_StylisticSet18, f == CanvasTypographyFeatureName.StylisticSet18); Set(XamlPropertyIndex.Typography_StylisticSet19, f == CanvasTypographyFeatureName.StylisticSet19); Set(XamlPropertyIndex.Typography_StylisticSet20, f == CanvasTypographyFeatureName.StylisticSet20); }
bool IsNamedFeature(CanvasTypographyFeatureName name) { // // DWrite and Win2D support a pre-defined list of typographic features. // However, fonts are free to expose features outside of that list. // In fact, many built-in fonts have such custom features. // // These custom features are also accessible through Win2D, and // are reported by GetSupportedTypographicFeatureNames. // var allValues = Enum.GetValues(typeof(CanvasTypographyFeatureName)); foreach (var value in allValues) { if ((CanvasTypographyFeatureName)(value) == name) return true; } return false; }
private void ApplyTypography() { /* * Here we shall map DirectWrite / Win2D typography properties to their * XAML equivalents. Not all properties are supported because not all * properties map directly. To support them all, we'd have to render all * the characters in the GridView with Win2D; */ if (AssociatedObject == null) { return; } // Hack to avoid XAML Direct crash if (_xamlDirect == null && TypographyFeature == null) { return; } if (_xamlDirect == null) { _xamlDirect = Utils.GetXamlDirectForWindow(Dispatcher); } /* Assign shorthands for use below */ CanvasTypographyFeatureName f = TypographyFeature == null ? CanvasTypographyFeatureName.None : TypographyFeature.Feature; TextBlock t = AssociatedObject; /* XAML Direct Helpers. Using XD is faster than setting Dependency Properties */ object o = _xamlDirect.GetXamlDirectObject(t); void Set(XamlPropertyIndex index, bool value) { _xamlDirect.SetBooleanProperty(o, index, value); } void SetE(XamlPropertyIndex index, uint e) { _xamlDirect.SetEnumProperty(o, index, e); } void SetI(XamlPropertyIndex index, bool val) { _xamlDirect.SetInt32Property(o, index, val ? 1 : 0); } /* TODO : ADD EASTASIAN TYPOGRAPY PROPERTIES */ /* Set CAPTIAL SPACING */ /* As Capital Spacing affects character spacing, it has no use when displaying single glyphs */ //Set(XamlPropertyIndex.Typography_CapitalSpacing, f == CanvasTypographyFeatureName.CapitalSpacing); /* Set KERNING */ /* As Kerning affects character spacing, it has no use when displaying single glyphs */ //Set(XamlPropertyIndex.Typography_Kerning, f == CanvasTypographyFeatureName.Kerning); /* Set SWASHES */ SetI(XamlPropertyIndex.Typography_StandardSwashes, f == CanvasTypographyFeatureName.Swash); SetI(XamlPropertyIndex.Typography_ContextualSwashes, f == CanvasTypographyFeatureName.ContextualSwash); /* Set ALTERNATES */ SetI(XamlPropertyIndex.Typography_AnnotationAlternates, f == CanvasTypographyFeatureName.AlternateAnnotationForms); SetI(XamlPropertyIndex.Typography_StylisticAlternates, f == CanvasTypographyFeatureName.StylisticAlternates); /* Contextual Alternates applies to combinations of characters, and as such has no purpose here yet */ Set(XamlPropertyIndex.Typography_ContextualAlternates, f == CanvasTypographyFeatureName.ContextualAlternates); /* Set MATHEMATICAL GREEK */ Set(XamlPropertyIndex.Typography_MathematicalGreek, f == CanvasTypographyFeatureName.MathematicalGreek); /* Set FORMS */ Set(XamlPropertyIndex.Typography_HistoricalForms, f == CanvasTypographyFeatureName.HistoricalForms); Set(XamlPropertyIndex.Typography_CaseSensitiveForms, f == CanvasTypographyFeatureName.CaseSensitiveForms); Set(XamlPropertyIndex.Typography_EastAsianExpertForms, f == CanvasTypographyFeatureName.ExpertForms); /* Set SLASHED ZERO */ Set(XamlPropertyIndex.Typography_SlashedZero, f == CanvasTypographyFeatureName.SlashedZero); /* Set LIGATURES */ /* Ligatures only apply to combinations of characters, and as such have no purpose here yet */ // Set(XamlPropertyIndex.Typography_StandardLigatures, f == CanvasTypographyFeatureName.StandardLigatures); // Set(XamlPropertyIndex.Typography_ContextualLigatures, f == CanvasTypographyFeatureName.ContextualLigatures); // Set(XamlPropertyIndex.Typography_HistoricalLigatures, f == CanvasTypographyFeatureName.HistoricalLigatures); // Set(XamlPropertyIndex.Typography_DiscretionaryLigatures, f == CanvasTypographyFeatureName.DiscretionaryLigatures); /* Set CAPITALS */ if (f == CanvasTypographyFeatureName.SmallCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.SmallCaps); } else if (f == CanvasTypographyFeatureName.SmallCapitalsFromCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.AllSmallCaps); } else if (f == CanvasTypographyFeatureName.PetiteCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.PetiteCaps); } else if (f == CanvasTypographyFeatureName.PetiteCapitalsFromCapitals) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.AllPetiteCaps); } else if (f == CanvasTypographyFeatureName.Titling) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Titling); } else if (f == CanvasTypographyFeatureName.Unicase) { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Unicase); } else { SetE(XamlPropertyIndex.Typography_Capitals, (uint)FontCapitals.Normal); } /* Set NUMERAL ALIGNMENT */ /* Numeral Alignment only apply to combinations of characters, and as such have no purpose here yet */ //if (f == CanvasTypographyFeatureName.ProportionalFigures) // SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Proportional); //else if (f == CanvasTypographyFeatureName.TabularFigures) // SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Tabular); //else SetE(XamlPropertyIndex.Typography_NumeralAlignment, (uint)FontNumeralAlignment.Normal); /* Set NUMERAL STYLE */ if (f == CanvasTypographyFeatureName.OldStyleFigures) { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.OldStyle); } else if (f == CanvasTypographyFeatureName.LiningFigures) { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.Lining); } else { SetE(XamlPropertyIndex.Typography_NumeralStyle, (uint)FontNumeralStyle.Normal); } /* Set VARIANTS */ if (f == CanvasTypographyFeatureName.Ordinals) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Ordinal); } else if (f == CanvasTypographyFeatureName.Superscript) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Superscript); } else if (f == CanvasTypographyFeatureName.Subscript) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Subscript); } else if (f == CanvasTypographyFeatureName.RubyNotationForms) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Ruby); } else if (f == CanvasTypographyFeatureName.ScientificInferiors) { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Inferior); } else { SetE(XamlPropertyIndex.Typography_Variants, (uint)FontVariants.Normal); } /* Set STLYISTIC SETS */ Set(XamlPropertyIndex.Typography_StylisticSet1, f == CanvasTypographyFeatureName.StylisticSet1); Set(XamlPropertyIndex.Typography_StylisticSet2, f == CanvasTypographyFeatureName.StylisticSet2); Set(XamlPropertyIndex.Typography_StylisticSet3, f == CanvasTypographyFeatureName.StylisticSet3); Set(XamlPropertyIndex.Typography_StylisticSet4, f == CanvasTypographyFeatureName.StylisticSet4); Set(XamlPropertyIndex.Typography_StylisticSet5, f == CanvasTypographyFeatureName.StylisticSet5); Set(XamlPropertyIndex.Typography_StylisticSet6, f == CanvasTypographyFeatureName.StylisticSet6); Set(XamlPropertyIndex.Typography_StylisticSet7, f == CanvasTypographyFeatureName.StylisticSet7); Set(XamlPropertyIndex.Typography_StylisticSet8, f == CanvasTypographyFeatureName.StylisticSet8); Set(XamlPropertyIndex.Typography_StylisticSet9, f == CanvasTypographyFeatureName.StylisticSet9); Set(XamlPropertyIndex.Typography_StylisticSet10, f == CanvasTypographyFeatureName.StylisticSet10); Set(XamlPropertyIndex.Typography_StylisticSet11, f == CanvasTypographyFeatureName.StylisticSet11); Set(XamlPropertyIndex.Typography_StylisticSet12, f == CanvasTypographyFeatureName.StylisticSet12); Set(XamlPropertyIndex.Typography_StylisticSet13, f == CanvasTypographyFeatureName.StylisticSet13); Set(XamlPropertyIndex.Typography_StylisticSet14, f == CanvasTypographyFeatureName.StylisticSet14); Set(XamlPropertyIndex.Typography_StylisticSet15, f == CanvasTypographyFeatureName.StylisticSet15); Set(XamlPropertyIndex.Typography_StylisticSet16, f == CanvasTypographyFeatureName.StylisticSet16); Set(XamlPropertyIndex.Typography_StylisticSet17, f == CanvasTypographyFeatureName.StylisticSet17); Set(XamlPropertyIndex.Typography_StylisticSet18, f == CanvasTypographyFeatureName.StylisticSet18); Set(XamlPropertyIndex.Typography_StylisticSet19, f == CanvasTypographyFeatureName.StylisticSet19); Set(XamlPropertyIndex.Typography_StylisticSet20, f == CanvasTypographyFeatureName.StylisticSet20); }