/// <summary> /// Method to handle inline replacement of style tag by closing style definition. /// </summary> /// <param name="charBuffer"></param> /// <param name="writeIndex"></param> /// <param name="styleStack"></param> /// <returns></returns> static void ReplaceClosingStyleTag(ref int[] charBuffer, ref int writeIndex, ref RichTextTagStack <int> styleStack) { // Get style from the Style Stack int hashCode = styleStack.CurrentItem(); TextStyle style = TextStyleSheet.GetStyle(hashCode); styleStack.Remove(); // Return if we don't have a valid style. if (style == null) { return; } int styleLength = style.styleClosingTagArray.Length; // Replace <style> tag with opening definition int[] closingTagArray = style.styleClosingTagArray; for (int i = 0; i < styleLength; i++) { int c = closingTagArray[i]; if (c == 60) { if (IsTagName(ref closingTagArray, "<BR>", i)) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = 10; writeIndex += 1; i += 3; continue; } if (IsTagName(ref closingTagArray, "<STYLE=", i)) { int offset; if (ReplaceOpeningStyleTag(ref closingTagArray, i, out offset, ref charBuffer, ref writeIndex, ref styleStack)) { i = offset; continue; } } else if (IsTagName(ref closingTagArray, "</STYLE>", i)) { ReplaceClosingStyleTag(ref charBuffer, ref writeIndex, ref styleStack); // Strip </style> even if style is invalid. i += 7; continue; } } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = c; writeIndex += 1; } }
public static TextStyleSheet LoadDefaultStyleSheet() { TextStyleSheet.s_Instance = null; return(TextStyleSheet.instance); }
/// <summary> /// Method to handle inline replacement of style tag by opening style definition. /// </summary> /// <param name="sourceText"></param> /// <param name="srcIndex"></param> /// <param name="srcOffset"></param> /// <param name="charBuffer"></param> /// <param name="writeIndex"></param> /// <param name="styleStack"></param> /// <returns></returns> static bool ReplaceOpeningStyleTag(ref string sourceText, int srcIndex, out int srcOffset, ref int[] charBuffer, ref int writeIndex, ref RichTextTagStack <int> styleStack) { // Validate <style> tag. int hashCode = GetTagHashCode(ref sourceText, srcIndex + 7, out srcOffset); TextStyle style = TextStyleSheet.GetStyle(hashCode); // Return if we don't have a valid style. if (style == null || srcOffset == 0) { return(false); } styleStack.Add(style.hashCode); int styleLength = style.styleOpeningTagArray.Length; // Replace <style> tag with opening definition int[] openingTagArray = style.styleOpeningTagArray; for (int i = 0; i < styleLength; i++) { int c = openingTagArray[i]; if (c == 60) { if (IsTagName(ref openingTagArray, "<BR>", i)) { if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = 10; writeIndex += 1; i += 3; continue; } if (IsTagName(ref openingTagArray, "<STYLE=", i)) { int offset; if (ReplaceOpeningStyleTag(ref openingTagArray, i, out offset, ref charBuffer, ref writeIndex, ref styleStack)) { i = offset; continue; } } else if (IsTagName(ref openingTagArray, "</STYLE>", i)) { ReplaceClosingStyleTag(ref charBuffer, ref writeIndex, ref styleStack); // Strip </style> even if style is invalid. i += 7; continue; } } if (writeIndex == charBuffer.Length) { ResizeInternalArray(ref charBuffer); } charBuffer[writeIndex] = c; writeIndex += 1; } return(true); }