//-------------------------------------------------------------------- // // Public Methods // //--------------------------------------------------------------------- #region public Methods public static FixedSOMTextRun Create(Rect boundingRect, GeneralTransform transform, Glyphs glyphs, FixedNode fixedNode, int startIndex, int endIndex, bool allowReverseGlyphs) { if (String.IsNullOrEmpty(glyphs.UnicodeString) || glyphs.FontRenderingEmSize <= 0) { return(null); } FixedSOMTextRun run = new FixedSOMTextRun(boundingRect, transform, fixedNode, startIndex, endIndex); run._fontUri = glyphs.FontUri; run._cultureInfo = glyphs.Language.GetCompatibleCulture(); run._bidiLevel = glyphs.BidiLevel; run._isSideways = glyphs.IsSideways; run._fontSize = glyphs.FontRenderingEmSize; GlyphRun glyphRun = glyphs.ToGlyphRun(); GlyphTypeface gtf = glyphRun.GlyphTypeface; // Find font family // glyphs.FontUri, glyphRun.glyphTypeface gtf.FamilyNames.TryGetValue(run._cultureInfo, out run._fontFamily); if (run._fontFamily == null) { //Try getting the English name gtf.FamilyNames.TryGetValue(System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS, out run._fontFamily); } // Find font style (normal, italics, Oblique) // need to open Font file. run._fontStyle = gtf.Style; // Find font weight (bold, semibold, ExtraLight) run._fontWeight = gtf.Weight; // Find font stretch (UltraCondensed, SemiExpanded, etc) run._fontStretch = gtf.Stretch; //Height and width should be the same for x character run._defaultCharWidth = gtf.XHeight > 0 ? gtf.XHeight * glyphs.FontRenderingEmSize : glyphRun.AdvanceWidths[startIndex]; Transform trans = transform.AffineTransform; if (trans != null && !(trans.Value.IsIdentity)) { Matrix mat = trans.Value; double yScale = Math.Sqrt(mat.M12 * mat.M12 + mat.M22 * mat.M22); double xScale = Math.Sqrt(mat.M11 * mat.M11 + mat.M21 * mat.M21); run._fontSize *= yScale; run._defaultCharWidth *= xScale; } run._foreground = glyphs.Fill; String s = glyphs.UnicodeString; run.Text = s.Substring(startIndex, endIndex - startIndex); if (allowReverseGlyphs && run._bidiLevel == 0 && !run._isSideways && startIndex == 0 && endIndex == s.Length && String.IsNullOrEmpty(glyphs.CaretStops) && FixedTextBuilder.MostlyRTL(s)) { run._isReversed = true; run.Text = string.Create(run.Text.Length, run.Text, (destination, runText) => { for (int i = 0; i < destination.Length; i++) { destination[i] = runText[runText.Length - 1 - i]; } }); } if (s == "" && glyphs.Indices != null && glyphs.Indices.Length > 0) { run._isWhiteSpace = false; } else { run._isWhiteSpace = true; for (int i = 0; i < s.Length; i++) { if (!Char.IsWhiteSpace(s[i])) { run._isWhiteSpace = false; break; } } } return(run); }
// Token: 0x06002E37 RID: 11831 RVA: 0x000D0E28 File Offset: 0x000CF028 public static FixedSOMTextRun Create(Rect boundingRect, GeneralTransform transform, Glyphs glyphs, FixedNode fixedNode, int startIndex, int endIndex, bool allowReverseGlyphs) { if (string.IsNullOrEmpty(glyphs.UnicodeString) || glyphs.FontRenderingEmSize <= 0.0) { return(null); } FixedSOMTextRun fixedSOMTextRun = new FixedSOMTextRun(boundingRect, transform, fixedNode, startIndex, endIndex); fixedSOMTextRun._fontUri = glyphs.FontUri; fixedSOMTextRun._cultureInfo = glyphs.Language.GetCompatibleCulture(); fixedSOMTextRun._bidiLevel = glyphs.BidiLevel; fixedSOMTextRun._isSideways = glyphs.IsSideways; fixedSOMTextRun._fontSize = glyphs.FontRenderingEmSize; GlyphRun glyphRun = glyphs.ToGlyphRun(); GlyphTypeface glyphTypeface = glyphRun.GlyphTypeface; glyphTypeface.FamilyNames.TryGetValue(fixedSOMTextRun._cultureInfo, out fixedSOMTextRun._fontFamily); if (fixedSOMTextRun._fontFamily == null) { glyphTypeface.FamilyNames.TryGetValue(TypeConverterHelper.InvariantEnglishUS, out fixedSOMTextRun._fontFamily); } fixedSOMTextRun._fontStyle = glyphTypeface.Style; fixedSOMTextRun._fontWeight = glyphTypeface.Weight; fixedSOMTextRun._fontStretch = glyphTypeface.Stretch; fixedSOMTextRun._defaultCharWidth = ((glyphTypeface.XHeight > 0.0) ? (glyphTypeface.XHeight * glyphs.FontRenderingEmSize) : glyphRun.AdvanceWidths[startIndex]); Transform affineTransform = transform.AffineTransform; if (affineTransform != null && !affineTransform.Value.IsIdentity) { Matrix value = affineTransform.Value; double num = Math.Sqrt(value.M12 * value.M12 + value.M22 * value.M22); double num2 = Math.Sqrt(value.M11 * value.M11 + value.M21 * value.M21); fixedSOMTextRun._fontSize *= num; fixedSOMTextRun._defaultCharWidth *= num2; } fixedSOMTextRun._foreground = glyphs.Fill; string unicodeString = glyphs.UnicodeString; fixedSOMTextRun.Text = unicodeString.Substring(startIndex, endIndex - startIndex); if (allowReverseGlyphs && fixedSOMTextRun._bidiLevel == 0 && !fixedSOMTextRun._isSideways && startIndex == 0 && endIndex == unicodeString.Length && string.IsNullOrEmpty(glyphs.CaretStops) && FixedTextBuilder.MostlyRTL(unicodeString)) { char[] array = new char[fixedSOMTextRun.Text.Length]; for (int i = 0; i < fixedSOMTextRun.Text.Length; i++) { array[i] = fixedSOMTextRun.Text[fixedSOMTextRun.Text.Length - 1 - i]; } fixedSOMTextRun._isReversed = true; fixedSOMTextRun.Text = new string(array); } if (unicodeString == "" && glyphs.Indices != null && glyphs.Indices.Length > 0) { fixedSOMTextRun._isWhiteSpace = false; } else { fixedSOMTextRun._isWhiteSpace = true; for (int j = 0; j < unicodeString.Length; j++) { if (!char.IsWhiteSpace(unicodeString[j])) { fixedSOMTextRun._isWhiteSpace = false; break; } } } return(fixedSOMTextRun); }
// Token: 0x06002E76 RID: 11894 RVA: 0x000D289C File Offset: 0x000D0A9C private static string _ConstructPageString(Stream pageStream, bool reverseRTL) { XmlTextReader baseReader = new XmlTextReader(pageStream); XmlReader xmlReader = new XmlCompatibilityReader(baseReader, FixedFindEngine._predefinedNamespaces); xmlReader = XmlReader.Create(xmlReader, new XmlReaderSettings { IgnoreWhitespace = true, IgnoreComments = true, ProhibitDtd = true }); xmlReader.MoveToContent(); StringBuilder stringBuilder = new StringBuilder(); bool flag = false; string text = null; while (xmlReader.Read()) { XmlNodeType nodeType = xmlReader.NodeType; if (nodeType == XmlNodeType.Element && xmlReader.Name == "Glyphs") { text = xmlReader.GetAttribute("UnicodeString"); if (!string.IsNullOrEmpty(text)) { string attribute = xmlReader.GetAttribute("IsSideways"); flag = false; if (attribute != null && string.Compare(attribute, bool.TrueString, StringComparison.OrdinalIgnoreCase) == 0) { flag = true; } if (reverseRTL) { string attribute2 = xmlReader.GetAttribute("BidiLevel"); int num = 0; if (!string.IsNullOrEmpty(attribute2)) { try { num = Convert.ToInt32(attribute2, CultureInfo.InvariantCulture); } catch (Exception) { } } string attribute3 = xmlReader.GetAttribute("CaretStops"); if (num == 0 && !flag && string.IsNullOrEmpty(attribute3) && FixedTextBuilder.MostlyRTL(text)) { char[] array = text.ToCharArray(); Array.Reverse(array); text = new string(array); } } stringBuilder.Append(text); } } } return(stringBuilder.ToString()); }
private static String _ConstructPageString(Stream pageStream, bool reverseRTL) { Debug.Assert(pageStream != null); XmlTextReader xmlTextReader = new XmlTextReader(pageStream); //Wrap around a compatibility reader XmlReader xmlReader = new XmlCompatibilityReader(xmlTextReader, _predefinedNamespaces); XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; settings.IgnoreComments = true; settings.ProhibitDtd = true; xmlReader = XmlReader.Create(xmlReader, settings); xmlReader.MoveToContent(); StringBuilder pageString = new StringBuilder(); bool isSideways = false; string unicodeStr = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: { if (xmlReader.Name == "Glyphs") { unicodeStr = xmlReader.GetAttribute("UnicodeString"); if (!String.IsNullOrEmpty(unicodeStr)) { string sidewaysString = xmlReader.GetAttribute("IsSideways"); isSideways = false; if (sidewaysString != null && String.Compare(sidewaysString, Boolean.TrueString, StringComparison.OrdinalIgnoreCase) == 0) { isSideways = true; } if (reverseRTL) { //This is to cover for MXDW generation //RTL Glyphs are saved LTR and bidi level is not set //In this case we need to reverse the UnicodeString string bidiLevelAsString = xmlReader.GetAttribute("BidiLevel"); int bidiLevel = 0; if (!String.IsNullOrEmpty(bidiLevelAsString)) { try { bidiLevel = Convert.ToInt32(bidiLevelAsString, CultureInfo.InvariantCulture); } catch (Exception) { } } string caretStops = xmlReader.GetAttribute("CaretStops"); if (bidiLevel == 0 && !isSideways && String.IsNullOrEmpty(caretStops) && FixedTextBuilder.MostlyRTL(unicodeStr)) { char[] chars = unicodeStr.ToCharArray(); Array.Reverse(chars); unicodeStr = new String(chars); } } pageString.Append(unicodeStr); } } } break; } } return(pageString.ToString()); }