private void ParseTHTD(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("th: {0}, {1}", node.Name, node.InnerText)); } _currentParagraph = CreateParagraph(); if (IsTH(node)) { _currentParagraph.HorizontalAlignment = HorizontalAlignment.Center; } ParseFlows(node); if (_currentParagraph != null && !_currentParagraph.IsEmpty) { if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } } if (_currentStyledText != null) { _currentCell.StyledText = _currentStyledText; } _currentParagraph = null; _currentStyledText = null; }
private void ParseParagraph(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("paragraph: {0}, {1}", node.Name, node.InnerText)); } _currentParagraph = CreateParagraph(); ParseInlines(node); if (_currentParagraph == null || _currentParagraph.IsEmpty) { return; } if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } SetParagraphKind(_currentParagraph, GetParagraphKind(node)); if (IsPre(node)) { var indent = new IndentParagraphCommand(_currentParagraph); indent.Execute(); } }
protected override void RefreshEditor(RefreshContext context, SimpleRect figure, UmlOperation model) { var text = UmlTextUtil.GetOperationText(model); var run = new Run(text); var para = new Paragraph(run) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Left, }; var st = new StyledText.Core.StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = Mkamo.Common.DataType.VerticalAlignment.Center, }; if (model.IsStatic) { run.Font = new FontDescription(run.Font, run.Font.Style | FontStyle.Underline); } if (model.IsAbstract) { run.Font = new FontDescription(run.Font, run.Font.Style | FontStyle.Italic); } figure.StyledText = st; figure.AdjustSize(); var clsFig = Host.Parent.Parent.Figure as INode; if (clsFig != null) { clsFig.AdjustSize(); } }
private void ParseDefListDescription(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("dd: {0}, {1}", node.Name, node.InnerText)); } _indent = true; _currentParagraph = CreateParagraph(); ParseFlows(node); if (_currentParagraph == null || _currentParagraph.IsEmpty) { return; } if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); //SetListItemProps(_currentParagraph, ListKind.Unordered, 1); } else { _currentStyledText.Add(_currentParagraph); //SetListItemProps(_currentParagraph, ListKind.Unordered, 1); } _indent = false; }
private void ParseListItem(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("li: {0}, {1}", node.Name, node.InnerText)); } _currentParagraph = CreateParagraph(); ParseFlows(node); if (_currentParagraph == null || _currentParagraph.IsEmpty) { return; } if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } _currentParagraph = null; }
private void ParseDefListTerm(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("dt: {0}, {1}", node.Name, node.InnerText)); } //_currentParagraph = CreateParagraph(); _currentParagraph = new Paragraph(); ParseInlines(node); if (_currentParagraph == null || _currentParagraph.IsEmpty) { return; } if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); //SetListItemProps(_currentParagraph, ListKind.Unordered, 0); } else { _currentStyledText.Add(_currentParagraph); //SetListItemProps(_currentParagraph, ListKind.Unordered, 0); } }
private StyledText.Core.StyledText CreateLabelStyledText(string text) { var run = new Run(text); var para = new Paragraph(run); var ret = new StyledText.Core.StyledText(para); run.Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(); return(ret); }
protected override void RefreshEditor(RefreshContext context, UmlClassFigure figure, UmlClass model) { var stereotypeRun = string.IsNullOrEmpty(model.Stereotype)? null: new Run(UmlTextUtil.GetStereotypeText(model)); var nameRun = new Run(model.Name); var para = default(Paragraph); if (stereotypeRun == null) { para = new Paragraph(nameRun) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Center, }; } else { para = new Paragraph(stereotypeRun) { Padding = Insets.Empty, HorizontalAlignment = Mkamo.Common.DataType.HorizontalAlignment.Center, }; var line = new LineSegment(); line.InsertBefore(nameRun); para.InsertAfter(line); } var st = new StyledText.Core.StyledText(para) { Font = MemopadApplication.Instance.Settings.GetDefaultUmlFont(), VerticalAlignment = Mkamo.Common.DataType.VerticalAlignment.Top, }; if (model.IsAbstract) { nameRun.Font = new FontDescription(nameRun.Font, nameRun.Font.Style | FontStyle.Italic); } figure.StyledText = st; var layout = (ListLayout)figure.Layout; layout.Padding = new Insets( 0, figure.StyledTextBounds.Height + figure.Padding.Height, 0, 0 ); figure.InvalidateLayout(); figure.AdjustSize(); UpdateMemoMarkHandles(model); }
// ======================================== // method // ======================================== public override void Execute() { _newStyledText = null; _oldStyledText = null; _command = null; _oldTargetAnchorId = null; if (_connectingAnchor.Kind == ConnectionAnchorKind.Source) { _command = new ConnectCommand(_target, _connectingAnchor, _newConnectableEditor, _newLocation); _command.Execute(); } else { var edge = _target.Figure as IEdge; _oldTargetAnchorId = edge.TargetConnectionOption as string; if (_newConnectableEditor == null) { _command = new ConnectCommand(_target, _connectingAnchor, _newConnectableEditor, _newLocation); _command.Execute(); } else { var node = _newConnectableEditor.Figure as INode; var model = _newConnectableEditor.Model as MemoText; _oldStyledText = model.StyledText.CloneDeeply() as StyledText.Core.StyledText; _newStyledText = model.StyledText; var charIndex = node.GetCharIndexAt(_newLocation); var inline = node.StyledText.GetInlineAt(charIndex); var anc = default(Anchor); if (inline.IsAnchorCharacter) { anc = inline as Anchor; } else { /// nodeのcharIndex位置にAnchor追加 anc = new Anchor(); var insertAnchorCommand = new InsertInlineCommand(_newStyledText, charIndex, anc); insertAnchorCommand.Execute(); } _newTargetAnchorId = anc.Id; edge.TargetConnectionOption = _newTargetAnchorId; _command = new ConnectCommand(_target, _connectingAnchor, _newConnectableEditor, _newLocation); _command.Execute(); } } }
public static void Save(string filename, StyledText.Core.StyledText stext) { using (var fs = new FileStream(filename, FileMode.OpenOrCreate)) using (var writer = XmlDictionaryWriter.CreateBinaryWriter(fs)) { var ser = new DataContractSerializer(typeof(StyledText.Core.StyledText), null, int.MaxValue, false, true, null); //ser.WriteObject(fs, stext); ser.WriteObject(writer, stext); writer.Close(); fs.Close(); } }
// ======================================== // constructor // ======================================== public MemoTable ParseCsv(string csv) { if (StringUtil.IsNullOrWhitespace(csv)) { return(null); } /// Excelでコピーした場合, /// 最後に\0が付いているので取り除いておく if (csv[csv.Length - 1] == '\0') { csv = csv.Remove(csv.Length - 1); } var ret = MemoFactory.CreateTable(); try { using (var reader = new CsvReader(new StringReader(csv), false)) { reader.MissingFieldAction = MissingFieldAction.ReplaceByEmpty; var colCount = reader.FieldCount; for (int i = 0; i < colCount; ++i) { ret.AddColumn(); } while (reader.ReadNextRecord()) { var row = ret.AddRow(); for (int i = 0; i < colCount; ++i) { var stext = new StyledText.Core.StyledText(); stext.Font = MemopadApplication.Instance.Settings.GetDefaultMemoTextFont(); var referer = new StyledTextReferer(stext, null, null, null, null); referer.InsertText(reader[i], false); var cell = row.Cells.ElementAt(i); cell.StyledText = stext; } } } } catch (Exception e) { Logger.Warn("Parse csv failed.", e); MemopadApplication.Instance.Container.Remove(ret); return(null); } return(ret); }
// ======================================== // method // ======================================== public IEnumerable <object> ParseCFHtml(string cfHtml) { _result = new List <object>(); _contexts = new Stack <ParserContext>(); _source = ClipboardUtil.GetHtmlSourceUrl(cfHtml); var html = Sanitize(cfHtml); var doc = new HtmlDocument(); doc.LoadHtml(html); var node = doc.DocumentNode; var bodies = doc.DocumentNode.SelectNodes(@"//html/body"); if (bodies == null || bodies.Count == 0) { return(_result); } var body = bodies[0]; ParseFlows(body); if (_currentParagraph != null) { /// Blockに囲まれていないInlineで終わった場合 if (!_currentParagraph.IsEmpty) { if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } } _currentParagraph = null; } if (_currentStyledText != null) { _result.Add(_currentStyledText); } return(_result); }
public static void EmptyCell(IEditor editor) { var model = editor.Model as MemoTableCell; if (model != null) { var oldStext = model.StyledText; var newStext = new StyledText.Core.StyledText(); var cmd = new DelegatingCommand( () => model.StyledText = newStext, () => model.StyledText = oldStext ); editor.Site.CommandExecutor.Execute(cmd); } }
private void ParseTable(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("table: {0}, {1}", node.Name, node.InnerText)); } /// 一時的に退避 var para = _currentParagraph; var stext = _currentStyledText; var inBlockQuote = _indent; var contexts = new Stack <ParserContext>(_contexts); _currentStyledText = null; _currentParagraph = null; _indent = false; _contexts = new Stack <ParserContext>(); var hasError = false; if (_currentTable == null) { _currentTable = MemoFactory.CreateTable(); _isFirstRow = true; try { ParseTableContent(node); } catch (Exception e) { Logger.Warn("Parse table error.", e); MemopadApplication.Instance.Container.Remove(_currentTable); _currentTable = null; hasError = true; } } else { /// 入れ子tableはInnerTextを貼りつけておくだけ ParseText(GetInnerText(node), null, true); return; } _currentParagraph = para; _currentStyledText = stext; _indent = inBlockQuote; _contexts = new Stack <ParserContext>(contexts); if (hasError) { /// 失敗したらInnerTextを貼りつけておくだけ ParseText(GetInnerText(node), null, true); } if (_currentTable != null && (_currentTable.RowCount == 0 || _currentTable.ColumnCount == 0)) { MemopadApplication.Instance.Container.Remove(_currentTable); return; } if (_currentParagraph != null && !_currentParagraph.IsEmpty) { if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } } _currentParagraph = null; if (_currentStyledText != null) { _result.Add(_currentStyledText); _currentStyledText = null; } if (_currentTable != null) { _result.Add(_currentTable); _currentTable = null; } }
private void SetUp(IEditor createdEditor, object model) { _newStyledText = null; _oldStyledText = null; /// 親controllerへの通知 var containerCtrl = _target.Controller as IContainerController; Contract.Requires( containerCtrl != null && containerCtrl.CanContainChild(_modelFactory.ModelDescriptor) ); var createdConnectionCtrl = createdEditor.Controller as IConnectionController; var createdEdge = createdEditor.Figure as IEdge; if (createdEditor == null || createdConnectionCtrl == null || createdEdge == null) { /// rollback containerCtrl.RemoveChild(model); _target.RemoveChildEditor(createdEditor); throw new ArgumentException(); } var srcConnectableCtrl = _edgeSourceEditor == null? null: _edgeSourceEditor.Controller as IConnectableController; var srcConnectableFig = _edgeSourceEditor == null? null: _edgeSourceEditor.Figure as IConnectable; var tgtConnectableCtrl = _edgeTargetEditor == null? null: _edgeTargetEditor.Controller as IConnectableController; var tgtConnectableFig = _edgeTargetEditor == null? null: _edgeTargetEditor.Figure as IConnectable; /// パラメタの妥当性検査 var isValidSrcConnect = _edgeSourceEditor != null && srcConnectableFig != null && createdConnectionCtrl.CanConnectSource(_edgeSourceEditor.Model); var isValidSrcDisconnect = (_edgeSourceEditor == null || srcConnectableCtrl == null || !createdConnectionCtrl.CanConnectSource(_edgeSourceEditor.Model) ) && createdConnectionCtrl.CanDisconnectSource; var isValidSrc = isValidSrcConnect || isValidSrcDisconnect; var isValidTgtConnect = _edgeTargetEditor != null && tgtConnectableCtrl != null && createdConnectionCtrl.CanConnectTarget(_edgeTargetEditor.Model); var isValidTgtDisconnect = (_edgeTargetEditor == null || tgtConnectableCtrl == null || !createdConnectionCtrl.CanConnectTarget(_edgeTargetEditor.Model) ) && createdConnectionCtrl.CanDisconnectTarget; var isValidTgt = isValidTgtConnect || isValidTgtDisconnect; if (!isValidSrc || !isValidTgt) { /// rollback containerCtrl.RemoveChild(model); _target.RemoveChildEditor(createdEditor); throw new ArgumentException(); } /// controllerの通知 if (isValidSrcConnect) { createdConnectionCtrl.ConnectSource(_edgeSourceEditor.Model); srcConnectableCtrl.ConnectOutgoing(model); } if (isValidTgtConnect) { createdConnectionCtrl.ConnectTarget(_edgeTargetEditor.Model); tgtConnectableCtrl.ConnectIncoming(model); var node = _edgeTargetEditor.Figure as INode; var mtext = _edgeTargetEditor.Model as MemoText; _oldStyledText = mtext.StyledText.CloneDeeply() as StyledText.Core.StyledText; _newStyledText = mtext.StyledText; var charIndex = node.GetCharIndexAt(_edgePoints.Last()); var inline = node.StyledText.GetInlineAt(charIndex); var anc = default(Anchor); if (inline.IsAnchorCharacter) { anc = inline as Anchor; } else { /// nodeのcharIndex位置にAnchor追加 anc = new Anchor(); var insertAnchorCommand = new InsertInlineCommand(_newStyledText, charIndex, anc); insertAnchorCommand.Execute(); } var edge = createdEdge; _newTargetAnchorId = anc.Id; _oldTargetAnchorId = edge.TargetConnectionOption as string; edge.TargetConnectionOption = _newTargetAnchorId; var connectCommand = new ConnectCommand(createdEditor, createdEdge.TargetAnchor, _edgeTargetEditor, _edgePoints.Last()); connectCommand.Execute(); } /// figureの編集 createdEdge.SetEdgePoints(_edgePoints); createdEdge.Route(); if (isValidSrcConnect) { createdEdge.Source = srcConnectableFig; } if (isValidTgtConnect) { createdEdge.Target = tgtConnectableFig; } createdEditor.Enable(); }
private void ParseImage(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("img: {0}, {1}", node.Name, node.InnerText)); } if (_currentTable != null) { /// table内は非対応 // todo: alt return; } var srcAttr = node.Attributes["src"]; if (srcAttr == null || StringUtil.IsNullOrWhitespace(srcAttr.Value)) { return; } var srcUri = new Uri(srcAttr.Value, UriKind.RelativeOrAbsolute); if (!srcUri.IsAbsoluteUri) { srcUri = new Uri(new Uri(_source), srcUri); } _WebClient.Headers["Referer"] = _source; var stream = default(Stream); var img = default(Image); try { stream = _WebClient.OpenRead(srcUri); img = Image.FromStream(stream); } catch (Exception e) { Logger.Warn("Can't load image.", e); return; } finally { if (stream != null) { stream.Dispose(); } } if (_currentParagraph != null) { if (!_currentParagraph.IsEmpty) { if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } } _currentParagraph = null; } if (_currentStyledText != null) { _result.Add(_currentStyledText); _currentStyledText = null; } _result.Add(img); }
private void ParseBlock(HtmlNode node) { if (Logger.IsDebugEnabled) { Logger.Debug(string.Format("block: {0}, {1}", node.Name, node.InnerText)); } if (_currentParagraph != null) { /// Blockに囲まれていないInlineのため if (!_currentParagraph.IsEmpty) { if (_currentStyledText == null) { _currentStyledText = CreateStyledText(_currentParagraph); } else { _currentStyledText.Add(_currentParagraph); } } _currentParagraph = null; } switch (node.Name.ToLowerInvariant()) { case "p": case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": ParseParagraph(node); break; case "pre": _inPre = true; ParseParagraph(node); _inPre = false; break; case "ul": case "ol": ParseList(node); break; case "li": _contexts.Push(CreateListContext(node)); ParseListItem(node); _contexts.Pop(); break; case "dl": ParseDefList(node); break; case "dt": ParseDefListTerm(node); break; case "dd": ParseDefListDescription(node); break; case "table": ParseTable(node); break; case "blockquote": _indent = true; ParseFlows(node); _indent = false; break; case "div": ParseFlows(node); break; } if (!IsDiv(node) && !IsBlockQuote(node)) { _currentParagraph = null; } }