", Style.Default);
- tw.Flush();
+ if (styles[i].Visible == 0)
+ tw.Write(" visibility: hidden;");
+ tw.WriteLine(" }");
+ }
- var tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32();
- var tab = new string(' ', tabSize);
+ tw.WriteLine("");
+ tw.Write(@"", Style.Default);
+ tw.Flush();
- tw.AutoFlush = true;
- var lastStyle = Style.Default;
- var unicodeLineEndings = ((scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0);
- foreach (var seg in styledSegments)
+ int tabSize = scintilla.DirectMessage(NativeMethods.SCI_GETTABWIDTH).ToInt32();
+ string tab = new(' ', tabSize);
+
+ tw.AutoFlush = true;
+ int lastStyle = Style.Default;
+ bool unicodeLineEndings = (scintilla.DirectMessage(NativeMethods.SCI_GETLINEENDTYPESACTIVE).ToInt32() & NativeMethods.SC_LINE_END_TYPE_UNICODE) > 0;
+ foreach (ArraySegment seg in styledSegments)
+ {
+ int endOffset = seg.Offset + seg.Count;
+ for (int i = seg.Offset; i < endOffset; i += 2)
{
- var endOffset = seg.Offset + seg.Count;
- for (int i = seg.Offset; i < endOffset; i += 2)
+ byte ch = seg.Array[i];
+ byte style = seg.Array[i + 1];
+
+ if (lastStyle != style)
{
- var ch = seg.Array[i];
- var style = seg.Array[i + 1];
+ tw.Write(@"", style);
+ lastStyle = style;
+ }
- if (lastStyle != style)
- {
- tw.Write(@"", style);
- lastStyle = style;
- }
+ switch (ch)
+ {
+ case (byte)'<':
+ tw.Write("<");
+ break;
- switch (ch)
- {
- case (byte)'<':
- tw.Write("<");
- break;
+ case (byte)'>':
+ tw.Write(">");
+ break;
- case (byte)'>':
- tw.Write(">");
- break;
+ case (byte)'&':
+ tw.Write("&");
+ break;
- case (byte)'&':
- tw.Write("&");
- break;
+ case (byte)'\t':
+ tw.Write(tab);
+ break;
- case (byte)'\t':
- tw.Write(tab);
- break;
+ case (byte)'\r':
+ if (i + 2 < endOffset)
+ {
+ if (seg.Array[i + 2] == (byte)'\n')
+ i += 2;
+ }
+
+ // Either way, this is a line break
+ goto case (byte)'\n';
- case (byte)'\r':
- if (i + 2 < endOffset)
+ case 0xC2:
+ if (unicodeLineEndings && i + 2 < endOffset)
+ {
+ if (seg.Array[i + 2] == 0x85) // NEL \u0085
{
- if (seg.Array[i + 2] == (byte)'\n')
- i += 2;
+ i += 2;
+ goto case (byte)'\n';
}
+ }
- // Either way, this is a line break
- goto case (byte)'\n';
+ // Not a Unicode line break
+ goto default;
- case 0xC2:
- if (unicodeLineEndings && i + 2 < endOffset)
+ case 0xE2:
+ if (unicodeLineEndings && i + 4 < endOffset)
+ {
+ if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028
{
- if (seg.Array[i + 2] == 0x85) // NEL \u0085
- {
- i += 2;
- goto case (byte)'\n';
- }
+ i += 4;
+ goto case (byte)'\n';
}
-
- // Not a Unicode line break
- goto default;
-
- case 0xE2:
- if (unicodeLineEndings && i + 4 < endOffset)
+ else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029
{
- if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA8) // LS \u2028
- {
- i += 4;
- goto case (byte)'\n';
- }
- else if (seg.Array[i + 2] == 0x80 && seg.Array[i + 4] == 0xA9) // PS \u2029
- {
- i += 4;
- goto case (byte)'\n';
- }
+ i += 4;
+ goto case (byte)'\n';
}
+ }
- // Not a Unicode line break
- goto default;
-
- case (byte)'\n':
- // All your line breaks are belong to us
- tw.Write("\r\n");
- break;
+ // Not a Unicode line break
+ goto default;
- default:
+ case (byte)'\n':
+ // All your line breaks are belong to us
+ tw.Write("\r\n");
+ break;
- if (ch == 0)
- {
- // Scintilla behavior is to allow control characters except for
- // NULL which will cause the Clipboard to truncate the string.
- tw.Write(" "); // Replace with space
- break;
- }
+ default:
- ms.WriteByte(ch);
+ if (ch == 0)
+ {
+ // Scintilla behavior is to allow control characters except for
+ // NULL which will cause the Clipboard to truncate the string.
+ tw.Write(" "); // Replace with space
break;
- }
+ }
+
+ ms.WriteByte(ch);
+ break;
}
}
-
- tw.AutoFlush = false;
- tw.WriteLine("
");
- tw.Flush();
-
- // Patch header
- pos = ms.Position;
- ms.Seek(INDEX_END_FRAGMENT, SeekOrigin.Begin);
- ms.Write((bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8"))), 0, bytes.Length);
- ms.Seek(pos, SeekOrigin.Begin);
- tw.WriteLine("");
-
- tw.WriteLine("");
- tw.WriteLine("");
- tw.Flush();
-
- // Patch header
- pos = ms.Position;
- ms.Seek(INDEX_END_HTML, SeekOrigin.Begin);
- ms.Write((bytes = Encoding.ASCII.GetBytes(ms.Length.ToString("D8"))), 0, bytes.Length);
- ms.Seek(pos, SeekOrigin.Begin);
-
- // Terminator
- ms.WriteByte(0);
-
- var str = GetString(ms.Pointer, (int)ms.Length, Encoding.UTF8);
- if (NativeMethods.SetClipboardData(CF_HTML, ms.Pointer) != IntPtr.Zero)
- ms.FreeOnDispose = false; // Clipboard will free memory
}
+
+ tw.AutoFlush = false;
+ tw.WriteLine("