/// <summary> /// Called by FontFamilyMapCollection when a FontFamilyMap is being added. /// </summary> internal void PrepareToAddFamilyMap(FontFamilyMap familyMap) { // Validate parameters. if (familyMap == null) { throw new ArgumentNullException("familyMap"); } if (string.IsNullOrEmpty(familyMap.Target)) { throw new ArgumentException(SR.Get(SRID.FamilyMap_TargetNotSet)); } // If it's culture-specific make sure it's in the hash table. if (familyMap.Language != null) { if (_familyMapRangesByLanguage == null) { _familyMapRangesByLanguage = new Dictionary <XmlLanguage, ushort[]>(InitialCultureCount); _familyMapRangesByLanguage.Add(familyMap.Language, EmptyFamilyMapRanges); } else if (!_familyMapRangesByLanguage.ContainsKey(familyMap.Language)) { _familyMapRangesByLanguage.Add(familyMap.Language, EmptyFamilyMapRanges); } } }
/// <summary> /// Gets the first FontFamilyMap that matches the specified Unicode scalar value. /// </summary> /// <param name="familyMapRanges">Return value of GetFamilyMapsOfCulture.</param> /// <param name="ch">Character to map.</param> /// <returns>FontFamilyMap or null.</returns> internal FontFamilyMap GetFamilyMapOfChar(ushort[] familyMapRanges, int ch) { Debug.Assert(IsFamilyMapRangesValid(familyMapRanges)); // Iterate over the ushort pairs in the skip list. for (int i = FirstFamilyMapRange; i < familyMapRanges.Length; i += 2) { // Each pair specifies a range in the family map list. int begin = familyMapRanges[i]; int end = familyMapRanges[i + 1]; Debug.Assert(begin < end && end <= _familyMaps.Count); // Iterate over the family maps in the specified range. for (int j = begin; j < end; ++j) { FontFamilyMap familyMap = _familyMaps[j]; Invariant.Assert(familyMap != null); if (familyMap.InRange(ch)) { return(familyMap); } } } return(FontFamilyMap.Default); }
/// <summary> /// Get family name correspondent to the first n-characters of the specified character string /// </summary> bool IFontFamily.GetMapTargetFamilyNameAndScale( CharacterBufferRange unicodeString, CultureInfo culture, CultureInfo digitCulture, double defaultSizeInEm, out int cchAdvance, out string targetFamilyName, out double scaleInEm ) { Invariant.Assert(unicodeString.CharacterBuffer != null && unicodeString.Length > 0); Invariant.Assert(culture != null); // Get the family map. This will find the first family map that matches // the specified culture, an ancestor neutral culture, or "any" culture. FontFamilyMap familyMap = GetTargetFamilyMap( unicodeString, culture, digitCulture, out cchAdvance ); // Return the values for the matching FontFamilyMap. If there is none this is // FontFamilyMap.Default which has Target == null and Scale == 1.0. targetFamilyName = familyMap.Target; scaleInEm = familyMap.Scale; return(true); }
public void Stub5() { FontFamilyMap fontFamilyMap = new FontFamilyMap(); // <SnippetFontMapSnippet5> fontFamilyMap.Language = XmlLanguage.GetLanguage("en-uk"); // </SnippetFontMapSnippet5> }
public void Stub3() { FontFamilyMap fontFamilyMap = new FontFamilyMap(); // <SnippetFontMapSnippet3> fontFamilyMap.Target = "Tahoma, Verdana"; // </SnippetFontMapSnippet3> }
public void Stub2() { FontFamilyMap fontFamilyMap = new FontFamilyMap(); // <SnippetFontMapSnippet2> fontFamilyMap.Scale = 1.1; // </SnippetFontMapSnippet2> }
public void Stub1() { // <SnippetFontMapSnippet1> FontFamilyMap fontFamilyMap = new FontFamilyMap(); // </SnippetFontMapSnippet1> fontFamilyMap.Target = "Tahoma, Verdana"; }
/// <summary> /// Parses the FontFamilyMap element, including its attributes and children, /// and advances to the next sibling element. /// </summary> private void ParseFamilyMapElement() { FontFamilyMap fmap = new FontFamilyMap(); // Parse the family map attributes. if (_reader.MoveToFirstAttribute()) { do { // Process attributes in the composite font namespace; ignore any others. if (IsCompositeFontAttribute()) { string name = _reader.LocalName; if (name == UnicodeAttribute) { fmap.Unicode = GetAttributeValue(); } else if (name == TargetAttribute) { fmap.Target = GetAttributeValue(); } else if (name == ScaleAttribute) { fmap.Scale = GetAttributeAsDouble(); } else if (name == LanguageAttribute) { fmap.Language = GetAttributeAsXmlLanguage(); } else { FailUnknownAttribute(); } } else if (!IsIgnorableAttribute()) { FailUnknownAttribute(); } } while (_reader.MoveToNextAttribute()); _reader.MoveToElement(); } _compositeFontInfo.FamilyMaps.Add(fmap); // There should be no child elements. ParseEmptyElement(); }
public void Stub4() { FontFamilyMap fontFamilyMap = new FontFamilyMap(); string unicode = fontFamilyMap.Unicode; // <SnippetFontMapSnippet4> try { fontFamilyMap.Unicode = "00e0-00ef, 0100-01ff"; } catch (FormatException ex) { // Handle exception } // </SnippetFontMapSnippet4> }
private ushort[] CreateFamilyMapRanges(XmlLanguage language) { // We could use an ArrayList, but a ushort[] is not much more code // and requires many fewer boxed objects. ushort[] ranges = new ushort[InitialFamilyMapRangesCapacity]; ranges[0] = (ushort)_familyMaps.Count; int count = 1; Debug.Assert(count == FirstFamilyMapRange); for (int i = 0; i < _familyMaps.Count; ++i) { if (FontFamilyMap.MatchLanguage(_familyMaps[i].Language, language)) { // grow ranges if necessary. if (count + 2 > ranges.Length) { ushort[] temp = new ushort[ranges.Length * 2 - FirstFamilyMapRange]; ranges.CopyTo(temp, 0); ranges = temp; } // beginning of range ranges[count++] = (ushort)i; ++i; while (i < _familyMaps.Count && FontFamilyMap.MatchLanguage(_familyMaps[i].Language, language)) { ++i; } // end of range, i.e., last index + 1 ranges[count++] = (ushort)i; } } // reallocate ranges to the exact size required if (count < ranges.Length) { ushort[] temp = new ushort[count]; Array.Copy(ranges, temp, count); ranges = temp; } return(ranges); }
public void Stub6() { // <SnippetFontMapSnippet6> // Create a new FontFamily object. FontFamily fontFamily = new FontFamily(); // Create the FontFamilyMap. FontFamilyMap fontFamilyMap = new FontFamilyMap(); fontFamilyMap.Target = "Comic Sans MS"; fontFamilyMap.Language = XmlLanguage.GetLanguage("en-us"); fontFamilyMap.Unicode = "00e0-00ef"; // Add the FontFamilyMap to the FontFamily's collection. fontFamily.FamilyMaps.Add(fontFamilyMap); // </SnippetFontMapSnippet6> }
private FontFamilyMap GetTargetFamilyMap( CharacterBufferRange unicodeString, CultureInfo culture, CultureInfo digitCulture, out int cchAdvance ) { DigitMap digitMap = new DigitMap(digitCulture); ushort[] familyMaps = _fontInfo.GetFamilyMapsOfLanguage(XmlLanguage.GetLanguage(culture.IetfLanguageTag)); int sizeofChar = 0; int ch = 0; // skip all the leading joinder characters. They need to be shaped with the // surrounding strong characters. cchAdvance = Classification.AdvanceWhile(unicodeString, ItemClass.JoinerClass); if (cchAdvance >= unicodeString.Length) { // It is rare that the run only contains joiner characters. // If it really happens, just map them to the initial family map. return(_fontInfo.GetFamilyMapOfChar( familyMaps, Classification.UnicodeScalar(unicodeString, out sizeofChar) )); } // // If the run starts with combining marks, we will not be able to find base characters for them // within the run. These combining marks will be mapped to their best fonts as normal characters. // ch = Classification.UnicodeScalar( new CharacterBufferRange(unicodeString, cchAdvance, unicodeString.Length - cchAdvance), out sizeofChar ); bool hasBaseChar = !Classification.IsCombining(ch); ch = digitMap[ch]; FontFamilyMap familyMap = _fontInfo.GetFamilyMapOfChar(familyMaps, ch); Invariant.Assert(familyMap != null); for (cchAdvance += sizeofChar; cchAdvance < unicodeString.Length; cchAdvance += sizeofChar) { ch = Classification.UnicodeScalar( new CharacterBufferRange(unicodeString, cchAdvance, unicodeString.Length - cchAdvance), out sizeofChar ); if (Classification.IsJoiner(ch)) { continue; // continue to advance if current char is a joiner } if (!Classification.IsCombining(ch)) { hasBaseChar = true; } else if (hasBaseChar) { continue; // continue to advance for combining mark with base char } ch = digitMap[ch]; if (_fontInfo.GetFamilyMapOfChar(familyMaps, ch) != familyMap) { break; } } return(familyMap); }
public FontFamilyMapItem(FontFamilyMap map) { Map = map; _ranges = ParseUnicodeRanges(Map.Unicode); }