private void _rtf_KeyDown(object sender, KeyEventArgs e) { RtfControl tb = sender as RtfControl; if (DocShortCut(e)) { return; } if (e.KeyValue == 71 && e.Control) { _rtf.GotoLine(); e.Handled = true; return; } if (string.IsNullOrEmpty(tb.SelectedText)) { return; } if (e.KeyValue == 222 && e.Shift) { tb.SelectedText = string.Format("\"{0}\"", tb.SelectedText); e.Handled = true; return; } if ((e.KeyValue == 57 || e.KeyValue == 48) && e.Shift) { tb.SelectedText = string.Format("({0})", tb.SelectedText); e.Handled = true; return; } if ((e.KeyValue == 219 || e.KeyValue == 221) && e.Shift) { tb.SelectedText = string.Format("{{{0}}}", tb.SelectedText); e.Handled = true; return; } if (e.KeyValue == 219 || e.KeyValue == 221) { tb.SelectedText = string.Format("[{0}]", tb.SelectedText); e.Handled = true; return; } if ((e.KeyValue == 188 || e.KeyValue == 190) && e.Shift) { tb.SelectedText = string.Format("<{0}>", tb.SelectedText); e.Handled = true; return; } if (e.KeyValue == 222) { tb.SelectedText = string.Format("'{0}'", tb.SelectedText); e.Handled = true; return; } }
public void Initialize(IReportItem forReportItem, ITargetDevice targetDevice) { _item = forReportItem; _control = _item as RtfControl; _computedSize = new SizeF(_item.Width.ToTwips(), _item.Height.ToTwips()); ProcessGrow(); ProcessShrink(); }
public RtfEditorHelper(FormCodeLibrary mainform, TextBoxHelper textboxHelper) { _TextBoxHelper = textboxHelper; _mainform = mainform; _rtf = _mainform.rtfEditor; _rtf.TextChanged += RtfEditor_TextChanged; _rtf.MouseUp += _rtf_MouseUp; _rtf.KeyDown += _rtf_KeyDown; _rtf.RichTextConrol.SelectionChanged += RichTextConrol_SelectionChanged; }
public byte[] Decompress(byte[] data, bool enforceCrc) { RtfHeader header = new RtfHeader(data); if (header.compressionType.Equals("MELA")) { // uncompressed! byte[] outBytes = new byte[data.Length]; data.CopyTo(outBytes, 0); return(outBytes); } else if (header.compressionType.Equals("LZFu")) { if (enforceCrc) { var headerCrc = CRC(data, RtfHeader.Length); if (headerCrc != header.crc) { throw new ArgumentException("Header CRC is incorrect."); } } var dictionary = new byte[DictionaryLength]; using (var destination = new MemoryStream(header.uncompressedSize)) { Array.Copy(InitialDictionary, 0, dictionary, 0, InitialDictionary.Length); var dictionaryPtr = InitialDictionary.Length; try { int bytePtr = RtfHeader.Length; while (bytePtr < data.Length) { var control = new RtfControl(data[bytePtr]); var offset = 1; for (int j = 0; j < control.flags.Length; j++) { if (control.flags[j]) { destination.WriteByte(data[bytePtr + offset]); dictionary[dictionaryPtr] = data[bytePtr + offset]; dictionaryPtr++; dictionaryPtr %= DictionaryLength; } else { var word = (((int)(data[bytePtr + offset])) << 8) | data[bytePtr + offset + 1]; var upper = (word & 0xFFF0) >> 4; var lower = (word & 0xF) + 2; if (upper == dictionaryPtr) { return(destination.ToArray()); } for (int k = 0; k < lower; k++) { var correctedOffset = (upper + k); correctedOffset %= DictionaryLength; if (destination.Position == header.uncompressedSize) { return(destination.ToArray()); } destination.WriteByte(dictionary[correctedOffset]); dictionary[dictionaryPtr] = dictionary[correctedOffset]; dictionaryPtr++; dictionaryPtr %= DictionaryLength; } offset++; } offset++; } bytePtr += control.length; } } catch (Exception) { } // return partial result in case of error return(destination.ToArray()); } } throw new ApplicationException("Unrecognized compression type."); }