private void CreateDescription(IGlymaNode node, ref Paragraph paragraph) { //paragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK)); if (node.NodeDescription.Type == "Iframe") { if (ShowDescriptionIcon) { var descriptionIcon = new ImageInline(DescriptionIconStream, new Size(20, 15), "png"); paragraph.Inlines.Add(descriptionIcon); paragraph.Inlines.Add(new Span(" ")); } else { paragraph.Inlines.Add(new Span("Link: ") { FontSize = 12 }); } CreateLink(node.NodeDescription.Link, ref paragraph); } else { if (ShowDescriptionIcon) { var descriptionIcon = new ImageInline(DescriptionIconStream, new Size(20, 15), "png"); paragraph.Inlines.Add(descriptionIcon); paragraph.Inlines.Add(new Span(" ")); } else { paragraph.Inlines.Add(new Span("Description: ") { FontSize = 12 }); } var htmlFormatProvider = new HtmlFormatProvider(); var description = htmlFormatProvider.Import(node.NodeDescription.Description); foreach (var item in description.Sections) { var section = item.CreateDeepCopy() as Section; if (section != null) { foreach (var block in section.Blocks) { var para = block as Paragraph; if (para != null) { foreach (Span span in para.EnumerateChildrenOfType<Span>()) { span.FontSize = 12; } foreach (var inline in para.Inlines) { var theNewInLineItem = inline.CreateDeepCopy() as Inline; paragraph.Inlines.Add(theNewInLineItem); } } else { CurrentBlockCollection.Add(block.CreateDeepCopy() as Block); } } } } } }
private static Image CreateImage(ImageInline imageInline) { // TODO: Add animated gif support. var bitmapImage = new BitmapImage(); if (imageInline.RenderUrl.Contains(".svg")) { using (var bitmap = (new Svg.SvgImage().GetImage(imageInline.RenderUrl) as Svg.SvgDocument).Draw()) using (var memory = new MemoryStream()) { bitmap.Save(memory, ImageFormat.Png); memory.Position = 0; bitmapImage.BeginInit(); bitmapImage.StreamSource = memory; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.EndInit(); } } else { bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri(imageInline.RenderUrl, UriKind.Absolute); bitmapImage.EndInit(); } return(new Image() { Source = bitmapImage, Stretch = System.Windows.Media.Stretch.Uniform, StretchDirection = StretchDirection.DownOnly }); }
/// <summary> /// Converts the UI element into Table /// </summary> /// <param name="element">UI element</param> /// <returns>Table</returns> public static Table GenerateTable(UIElement element, String header = "") { Table contentTbl = new Table(); TableRow contentRow = new TableRow(); TableCell contentCell = new TableCell(); WriteableBitmap wb = new WriteableBitmap(element, null); ImageInline image = new ImageInline(wb); Telerik.Windows.Documents.Model.Paragraph p = new Telerik.Windows.Documents.Model.Paragraph(); p.Inlines.Add(image); contentCell.Blocks.Add(p); if (!String.IsNullOrEmpty(header)) { TableRow headerRow = new TableRow(); TableCell cell = new TableCell(); cell.Background = Color.FromArgb(255, 228, 229, 229); AddCellValue(cell, header); cell.PreferredWidth = new TableWidthUnit((float)element.RenderSize.Width); headerRow.Cells.Add(cell); contentTbl.Rows.Add(headerRow); } contentRow.Cells.Add(contentCell); contentTbl.Rows.Add(contentRow); return(contentTbl); }
private RadDocument CreateDocument() { RadDocument document = new RadDocument(); Section section = new Section(); Paragraph paragraph = new Paragraph(); MemoryStream ms = new MemoryStream(); radChart.ExportToImage(ms, new PngBitmapEncoder()); double imageWidth = radChart.ActualWidth; double imageHeight = radChart.ActualHeight; if (imageWidth > 625) { imageWidth = 625; imageHeight = radChart.ActualHeight * imageWidth / radChart.ActualWidth; } ImageInline image = new ImageInline(ms, new Size(imageWidth, imageHeight), "png"); paragraph.Inlines.Add(image); section.Blocks.Add(paragraph); document.Sections.Add(section); ms.Close(); return(document); }
private void RadWindow_Closed(object sender, WindowClosedEventArgs e) { this.Owner = null; this.originalImageInline = null; this.originalInline = null; this.replaceCurrentInlineCallback = null; }
private void AddInlineImageAtIndex(RadFlowDocument document, Paragraph paragraph) { #region radwordsprocessing-model-imageinline_1 ImageInline imageInline = new ImageInline(document); paragraph.Inlines.Insert(0, imageInline); #endregion }
public static void AddInlineImage() { WordDocument document = new WordDocument(); WordDocumentBuilder builder = new WordDocumentBuilder(document); //Add in-line image using builder builder.InsertText("Simple sentence 1 in line. "); using (Stream stream = File.OpenRead("sample.jpg")) { builder.InsertImageInline(stream, "jpg"); } builder.InsertText("Simple sentence 2 in line"); //Add in-line image using Paragraph object Paragraph paragraph = builder.InsertParagraph(); //Add text before TextInline textStart = paragraph.Inlines.AddText(); textStart.Text = "Text add using paragraph start."; //Insert image in the middle of text content ImageInline imageInline = paragraph.Inlines.AddImageInline(); using (Stream stream = File.OpenRead("sample.png")) { imageInline.Image.ImageSource = new Basic.Media.ImageSource(stream, "png"); } //Add text after TextInline textEnd = paragraph.Inlines.AddText(); textEnd.Text = "Text add using paragraph end."; WordFile wordFile = new WordFile(); File.WriteAllBytes("AddImageInline.docx", wordFile.Export(document)); }
private void ShowDialogInternal(Inline targetInline, Action<Inline, Inline> replaceCallback, RadRichTextBox owner) { if (targetInline is ImageInline) { this.originalImageInline = (ImageInline)targetInline; } else if (targetInline is FloatingImageBlock) { this.originalImageInline = ((FloatingImageBlock)targetInline).ImageInline; } else { throw new InvalidOperationException("Unable to find image element."); } this.SetOwner(owner); this.replaceCurrentInlineCallback = replaceCallback; this.originalInline = targetInline; this.ShowDialog(); this.Dispatcher.BeginInvoke(new Action(() => { this.FillUI(this.originalInline); })); }
public void ShowDialogInternal(Inline orgInline, Action<Inline, Inline> replaceCurrentImageCallback, string executeToolName, RadRichTextBox owner) { this.SetOwner(owner); this.originalInline = orgInline; if (orgInline is ImageInline) { this.originalImageInline = (ImageInline)orgInline; } else if (orgInline is FloatingImageBlock) { this.originalImageInline = ((FloatingImageBlock)orgInline).ImageInline; } else { throw new InvalidOperationException("Unable to find image element."); } RadBitmap image = new RadBitmap(this.originalImageInline.ImageSource); this.isRotated = false; this.originalAspect = new Size(this.originalImageInline.Width / image.Width, this.originalImageInline.Height / image.Height); this.originalRotateAngle = this.originalImageInline.RotateAngle; this.replaceCurrentImageCallback = replaceCurrentImageCallback; this.ImageEditorUI.Image = image; this.ShowDialog(); this.StartExecuteTool(executeToolName); }
private Inline CreateInlineToInsert() { Inline result; ImageInline imageInline = new ImageInline(this.originalImageInline); WrappingStyle?style = this.textWrappingProperties.GetWrappingStyle(); if (style == null) { //create image inline result = imageInline; } else { FloatingImageBlock imageBlock = new FloatingImageBlock(); imageBlock.ImageInline = imageInline; imageBlock.WrappingStyle = style.Value; imageBlock.TextWrap = this.textWrappingProperties.GetTextWrap(); imageBlock.Margin = this.textWrappingProperties.GetMargin(); imageBlock.VerticalPosition = this.positionProperties.GetVerticalPosition(); imageBlock.HorizontalPosition = this.positionProperties.GetHorizontalPosition(); imageBlock.AllowOverlap = this.positionProperties.GetAllowOverlap(); result = imageBlock; } return(result); }
/// <summary> /// Renders an image element. /// </summary> /// <param name="inlineCollection"> The list to add to. </param> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> private void RenderImage(InlineCollection inlineCollection, ImageInline element, RenderContext context) { var image = new Image(); var imageContainer = new InlineUIContainer() { Child = image }; // if url is not absolute we have to return as local images are not supported if (!element.Url.StartsWith("http") && !element.Url.StartsWith("ms-app")) { RenderTextRun(inlineCollection, new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); return; } image.Source = new BitmapImage(new Uri(element.Url)); image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Stretch = ImageStretch; ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { inlineCollection.Add(imageContainer); } catch { // Ignore error } }
public void ShowDialogInternal(Inline orgInline, Action <Inline, Inline> replaceCurrentImageCallback, string executeToolName, RadRichTextBox owner) { this.SetOwner(owner); this.originalInline = orgInline; if (orgInline is ImageInline) { this.originalImageInline = (ImageInline)orgInline; } else if (orgInline is FloatingImageBlock) { this.originalImageInline = ((FloatingImageBlock)orgInline).ImageInline; } else { throw new InvalidOperationException("Unable to find image element."); } RadBitmap image = new RadBitmap(this.originalImageInline.ImageSource); this.isRotated = false; this.originalAspect = new Size(this.originalImageInline.Width / image.Width, this.originalImageInline.Height / image.Height); this.originalRotateAngle = this.originalImageInline.RotateAngle; this.replaceCurrentImageCallback = replaceCurrentImageCallback; this.ImageEditorUI.Image = image; this.ShowDialog(); this.StartExecuteTool(executeToolName); }
private void OK_Click(object sender, RoutedEventArgs e) { if (this.replaceCurrentImageCallback != null) { this.ImageEditorUI.ImageEditor.CommitTool(); Inline reslut; ImageInline image = new ImageInline(this.ImageEditorUI.Image.Bitmap); image.CopyPropertiesFrom(this.originalImageInline); image.Size = new Size(image.Width * this.originalAspect.Width, image.Height * this.originalAspect.Height); if (this.isRotated) { image.Size = new Size(image.Size.Height, image.Size.Width); } image.RotateAngle = this.originalRotateAngle; if (this.originalInline is FloatingImageBlock) { FloatingImageBlock imageBlock = new FloatingImageBlock(); imageBlock.CopyPropertiesFrom(this.originalInline); imageBlock.ImageInline = image; reslut = imageBlock; } else { reslut = image; } this.replaceCurrentImageCallback(this.originalInline, reslut); } this.Close(); }
private void CreateInlineImage(RadFlowDocument document, Paragraph paragraph) { #region radwordsprocessing-model-imageinline_0 ImageInline imageInline = new ImageInline(document); paragraph.Inlines.Add(imageInline); #endregion }
private void FillUIFromImage(ImageInline image) { this.SetVerticalPosition(new FloatingBlockVerticalPosition(VerticalRelativeFrom.Paragraph, 0d)); this.SetHorizontalPosition(new FloatingBlockHorizontalPosition(HorizontalRelativeFrom.Paragraph, 0d)); this.SetAllowOverlap(false); this.SetIsEnabled(false); }
private Inline CreateInlineToInsert() { Inline result; ImageInline imageInline = new ImageInline(this.originalImageInline); WrappingStyle? style = this.textWrappingProperties.GetWrappingStyle(); if (style == null) { //create image inline result = imageInline; } else { FloatingImageBlock imageBlock = new FloatingImageBlock(); imageBlock.ImageInline = imageInline; imageBlock.WrappingStyle = style.Value; imageBlock.TextWrap = this.textWrappingProperties.GetTextWrap(); imageBlock.Margin = this.textWrappingProperties.GetMargin(); imageBlock.VerticalPosition = this.positionProperties.GetVerticalPosition(); imageBlock.HorizontalPosition = this.positionProperties.GetHorizontalPosition(); imageBlock.AllowOverlap = this.positionProperties.GetAllowOverlap(); result = imageBlock; } return result; }
private void ShowDialogInternal(Inline targetInline, Action <Inline, Inline> replaceCallback, RadRichTextBox owner) { if (targetInline is ImageInline) { this.originalImageInline = (ImageInline)targetInline; } else if (targetInline is FloatingImageBlock) { this.originalImageInline = ((FloatingImageBlock)targetInline).ImageInline; } else { throw new InvalidOperationException("Unable to find image element."); } this.SetOwner(owner); this.replaceCurrentInlineCallback = replaceCallback; this.originalInline = targetInline; this.ShowDialog(); this.Dispatcher.BeginInvoke(new Action(() => { this.FillUI(this.originalInline); })); }
public static Table CreateTableFrame(Table table) { ThemableColor bordersColor = new ThemableColor(Colors.Black); //Set table border table.Borders = new TableBorders(new Border(3, BorderStyle.Single, bordersColor)); table.TableCellPadding = new Basic.Primitives.Padding(6); TableRow row = table.Rows.AddTableRow(); //Add a merged cell in 2x2 TableCell cell = row.Cells.AddTableCell(); cell.RowSpan = 2; cell.ColumnSpan = 2; cell.Blocks.AddParagraph().Inlines.AddText("Text 1"); //Add a single cell cell = row.Cells.AddTableCell(); cell.Blocks.AddParagraph().Inlines.AddText("Text 2"); row = table.Rows.AddTableRow(); //Add a single cell cell = row.Cells.AddTableCell(); cell.Blocks.AddParagraph().Inlines.AddText("Text 3"); row = table.Rows.AddTableRow(); //Add a single cell cell = row.Cells.AddTableCell(); cell.Blocks.AddParagraph().Inlines.AddText("Text 4"); //Add a merged cell in 1x2 cell = row.Cells.AddTableCell(); cell.ColumnSpan = 2; cell.Blocks.AddParagraph().Inlines.AddText("Text 5"); row = table.Rows.AddTableRow(); //Add a single cell cell = row.Cells.AddTableCell(); cell.Blocks.AddParagraph().Inlines.AddText("Text 6"); //Add a single cell cell = row.Cells.AddTableCell(); cell.Blocks.AddParagraph().Inlines.AddText("Text 7"); //Add a single cell cell = row.Cells.AddTableCell(); ImageInline imageCell = cell.Blocks.AddParagraph().Inlines.AddImageInline(); using (Stream stream = File.OpenRead("watermark.png")) { imageCell.Image.ImageSource = new Basic.Media.ImageSource(stream, "png"); imageCell.Image.Width = 50; imageCell.Image.Height = 50; } return(table); }
private void CreateImage(string mapImageUrl, Section section) { Paragraph mapParagraph = new Paragraph(m_Document); ImageInline mapImageInline = mapParagraph.Inlines.AddImageInline(); GetMap(mapImageUrl, mapImageInline); mapImageInline.Image.Width = Convert.ToDouble(ConfigurationManager.AppSettings["imageWidth"]); mapImageInline.Image.Height = Convert.ToDouble(ConfigurationManager.AppSettings["imageHeight"]); section.Blocks.Add(mapParagraph); }
private void InsertPictureDialogOnInsertClicked(object sender, InsertImageEventArgs e) { var image = new ImageInline(); image.UriSource = e.Url; image.Extension = Path.GetExtension(e.Url.ToString()); image.Width = e.Width; image.Height = e.Height; // Insert the image at current caret position. RadRichTextBox.InsertInline(image); }
private void AddInlinesToParagraph(Paragraph paragraph) { #region radwordsprocessing-model-paragraph_4 Run run = paragraph.Inlines.AddRun(); #endregion #region radwordsprocessing-model-paragraph_5 ImageInline imageInline = paragraph.Inlines.AddImageInline(); #endregion #region radwordsprocessing-model-paragraph_6 FloatingImage floatingImage = paragraph.Inlines.AddFloatingImage(); #endregion }
static Common() { BoldTextInline.AddTripChars(_triggerList); ItalicTextInline.AddTripChars(_triggerList); MarkdownLinkInline.AddTripChars(_triggerList); HyperlinkInline.AddTripChars(_triggerList); StrikethroughTextInline.AddTripChars(_triggerList); SuperscriptTextInline.AddTripChars(_triggerList); CodeInline.AddTripChars(_triggerList); ImageInline.AddTripChars(_triggerList); // Create an array of characters to search against using IndexOfAny. _tripCharacters = _triggerList.Select(trigger => trigger.FirstChar).Distinct().ToArray(); }
private void GetMap(string imageUrl, ImageInline mapImageInline) { ; using (WebClient webClient = new WebClient()) { byte[] data = webClient.DownloadData(imageUrl); using (MemoryStream mem = new MemoryStream(data)) { mapImageInline.Image.ImageSource = new ImageSource(mem, "png"); } } }
internal void FillUI(Inline targetInline) { FloatingBlock flaotingBlock = targetInline as FloatingBlock; if (flaotingBlock != null) { this.FillUIFromFloatingBlock(flaotingBlock); } else { ImageInline image = targetInline as ImageInline; Debug.Assert(image != null, "Unexpected inline type"); if (image != null) { this.FillUIFromImage(image); } } }
public static ImageInline GetImage(string nodeType) { lock (_getImageLock) { if (Images.ContainsKey(nodeType)) { return new ImageInline(Images[nodeType]); } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Glyma.UtilityService.Export.Images." + nodeType + ".png")) { var image = new ImageInline(stream, new Size(21, 21), "png"); image.ImageSource.Freeze(); Images.Add(nodeType, image); return image; } } }
public static ImageInline GetImage(string nodeType) { lock (_getImageLock) { if (Images.ContainsKey(nodeType)) { return(new ImageInline(Images[nodeType])); } using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Glyma.UtilityService.Export.Images." + nodeType + ".png")) { var image = new ImageInline(stream, new Size(21, 21), "png"); image.ImageSource.Freeze(); Images.Add(nodeType, image); return(image); } } }
private Header CreateHeader() { RadDocument headerDocument = new RadDocument(); RadDocumentEditor editor = new RadDocumentEditor(headerDocument); using (Stream stream = Application.GetResourceStream(GetResourceUri("Images/Telerik_Logo.jpg")).Stream) { ImageInline image = new ImageInline(stream); editor.InsertInline(image); } editor.ChangeParagraphTextAlignment(RadTextAlignment.Center); Header header = new Header() { Body = headerDocument }; return(header); }
private void AddTemplateImageCommandExecuted() { var dialog = new Microsoft.Win32.OpenFileDialog() { Multiselect = false, Filter = "Image Files (*.bmp,*.png, *.jpg)|*.bmp;*.png;*.jpg" }; var result = dialog.ShowDialog(); if (result == true) { Image = new ImageInline { UriSource = new Uri(dialog.FileName, UriKind.Absolute), Width = 300, Height = 150, }; RaisePropertyChanged("InsertImage"); } }
private void ShowImageEditorDialog() { ImageInline imageInline = this.radRichTextBox.Document.EnumerateChildrenOfType <ImageInline>().FirstOrDefault(); if (imageInline != null) { DocumentPosition start = new DocumentPosition(this.radRichTextBox.Document); DocumentPosition end = new DocumentPosition(this.radRichTextBox.Document); start.MoveToInline(imageInline); end.MoveToPosition(start); end.MoveToNext(); this.radRichTextBox.Document.Selection.AddSelectionStart(start); this.radRichTextBox.Document.Selection.AddSelectionEnd(end); if (this.radRichTextBox.Document.Selection.GetSelectedSingleInline() is ImageInline) { this.radRichTextBox.ShowImageEditorDialog(); } } }
/// <summary> /// Renders an image element. /// </summary> /// <param name="inlineCollection"> The list to add to. </param> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> private async void RenderImage(InlineCollection inlineCollection, ImageInline element, RenderContext context) { var placeholder = RenderTextRun(inlineCollection, new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); var resolvedImage = await _imageResolver.ResolveImageAsync(element.Url, element.Tooltip); // if image can not be resolved we have to return if (resolvedImage == null) { return; } var image = new Image(); var imageContainer = new InlineUIContainer() { Child = image }; image.Source = resolvedImage; image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Top; image.Stretch = ImageStretch; ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { var placeholderIndex = inlineCollection.IndexOf(placeholder); inlineCollection.Remove(placeholder); inlineCollection.Insert(placeholderIndex, imageContainer); } catch { // Ignore error } }
/// <summary> /// Helper Method for printing Chart /// </summary> /// <param name="chart">The Chart to be Printed</param> private static RadDocument CreateChartDocumentPart(RadChart chart) { try { RadDocument document = new RadDocument(); Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section(); Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph(); BitmapImage bi = new BitmapImage(); using (MemoryStream ms = new MemoryStream()) { chart.ExportToImage(ms, new PngBitmapEncoder()); bi.SetSource(ms); } double imageWidth = chart.ActualWidth; double imageHeight = chart.ActualHeight; if (imageWidth > 625) { imageWidth = 625; imageHeight = chart.ActualHeight * imageWidth / chart.ActualWidth; } ImageInline image = new ImageInline(new WriteableBitmap(bi)) { Width = imageWidth, Height = imageHeight }; paragraph.Inlines.Add(image); section.Blocks.Add(paragraph); document.Sections.Add(section); return(document); } catch (Exception ex) { Prompt.ShowDialog("Message: " + ex.Message + "\nStackTrace: " + Logging.StackTraceToString(ex), "Exception", MessageBoxButton.OK); return(null); } }
/// <summary> /// Renders an image element. /// </summary> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> protected override async void RenderImage(ImageInline element, IRenderContext context) { var localContext = context as InlineRenderContext; if (localContext == null) { throw new RenderContextIncorrectException(); } var inlineCollection = localContext.InlineCollection; var placeholder = InternalRenderTextRun(new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); var resolvedImage = await ImageResolver.ResolveImageAsync(element.RenderUrl, element.Tooltip); // if image can not be resolved we have to return if (resolvedImage == null) { return; } var image = new Image { Source = resolvedImage, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, Stretch = ImageStretch }; HyperlinkButton hyperlinkButton = new HyperlinkButton() { Content = image }; var viewbox = new Viewbox { Child = hyperlinkButton, StretchDirection = Windows.UI.Xaml.Controls.StretchDirection.DownOnly }; viewbox.PointerWheelChanged += Preventative_PointerWheelChanged; var scrollViewer = new ScrollViewer { Content = viewbox, VerticalScrollMode = ScrollMode.Disabled, VerticalScrollBarVisibility = ScrollBarVisibility.Disabled }; var imageContainer = new InlineUIContainer() { Child = scrollViewer }; bool ishyperlink = false; if (element.RenderUrl != element.Url) { ishyperlink = true; } LinkRegister.RegisterNewHyperLink(image, element.Url, ishyperlink); if (ImageMaxHeight > 0) { viewbox.MaxHeight = ImageMaxHeight; } if (ImageMaxWidth > 0) { viewbox.MaxWidth = ImageMaxWidth; } if (element.ImageWidth > 0) { image.Width = element.ImageWidth; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0) { if (element.ImageWidth == 0) { image.Width = element.ImageHeight; } image.Height = element.ImageHeight; image.Stretch = Stretch.UniformToFill; } if (element.ImageHeight > 0 && element.ImageWidth > 0) { image.Stretch = Stretch.Fill; } // If image size is given then scroll to view overflown part if (element.ImageHeight > 0 || element.ImageWidth > 0) { scrollViewer.HorizontalScrollMode = ScrollMode.Auto; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; } // Else resize the image else { scrollViewer.HorizontalScrollMode = ScrollMode.Disabled; scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; } ToolTipService.SetToolTip(image, element.Tooltip); // Try to add it to the current inlines // Could fail because some containers like Hyperlink cannot have inlined images try { var placeholderIndex = inlineCollection.IndexOf(placeholder); inlineCollection.Remove(placeholder); inlineCollection.Insert(placeholderIndex, imageContainer); } catch { // Ignore error } }
/// <summary> /// Finds the next inline element by matching trip chars and verifying the match. /// </summary> /// <param name="markdown"> The markdown text to parse. </param> /// <param name="start"> The position to start parsing. </param> /// <param name="end"> The position to stop parsing. </param> /// <param name="ignoreLinks"> Indicates whether to parse links. </param> /// <returns>Returns the next element</returns> private static InlineParseResult FindNextInlineElement(string markdown, int start, int end, bool ignoreLinks) { // Search for the next inline sequence. for (int pos = start; pos < end; pos++) { // IndexOfAny should be the fastest way to skip characters we don't care about. pos = markdown.IndexOfAny(_tripCharacters, pos, end - pos); if (pos < 0) { break; } // Find the trigger(s) that matched. char currentChar = markdown[pos]; foreach (InlineTripCharHelper currentTripChar in _triggerList) { // Check if our current char matches the suffix char. if (currentChar == currentTripChar.FirstChar) { // Don't match if the previous character was a backslash. if (pos > start && markdown[pos - 1] == '\\') { continue; } // If we are here we have a possible match. Call into the inline class to verify. InlineParseResult parseResult = null; switch (currentTripChar.Method) { case InlineParseMethod.BoldItalic: parseResult = BoldItalicTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.Comment: parseResult = CommentInline.Parse(markdown, pos, end); break; case InlineParseMethod.LinkReference: parseResult = LinkAnchorInline.Parse(markdown, pos, end); break; case InlineParseMethod.Bold: parseResult = BoldTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.Italic: parseResult = ItalicTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.MarkdownLink: if (!ignoreLinks) { parseResult = MarkdownLinkInline.Parse(markdown, pos, end); } break; case InlineParseMethod.AngleBracketLink: if (!ignoreLinks) { parseResult = HyperlinkInline.ParseAngleBracketLink(markdown, pos, end); } break; case InlineParseMethod.Url: if (!ignoreLinks) { parseResult = HyperlinkInline.ParseUrl(markdown, pos, end); } break; case InlineParseMethod.RedditLink: if (!ignoreLinks) { parseResult = HyperlinkInline.ParseRedditLink(markdown, pos, end); } break; case InlineParseMethod.PartialLink: if (!ignoreLinks) { parseResult = HyperlinkInline.ParsePartialLink(markdown, pos, end); } break; case InlineParseMethod.Email: if (!ignoreLinks) { parseResult = HyperlinkInline.ParseEmailAddress(markdown, start, pos, end); } break; case InlineParseMethod.Strikethrough: parseResult = StrikethroughTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.Superscript: parseResult = SuperscriptTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.Subscript: parseResult = SubscriptTextInline.Parse(markdown, pos, end); break; case InlineParseMethod.Code: parseResult = CodeInline.Parse(markdown, pos, end); break; case InlineParseMethod.Image: parseResult = ImageInline.Parse(markdown, pos, end); break; case InlineParseMethod.Emoji: parseResult = EmojiInline.Parse(markdown, pos, end); break; } if (parseResult != null) { return(parseResult); } } } } // If we didn't find any elements we have a normal text block. // Let us consume the entire range. return(new InlineParseResult(TextRunInline.Parse(markdown, start, end), start, end)); }
private void FillUIFromImage(ImageInline image) { this.SetWrappingStyle(null); this.SetMargin(new Thickness()); this.SetTextWrap(TextWrap.BothSides); }
/// <summary> /// Takes a UI element converts it to an image. /// </summary> /// <param name="uiElement">The uiElement to add to the manifest</param> /// <param name="customForceLayoutUpdate">A custom method to force the ui element's layout.</param> private ImageInline ConvertToImageInline(UIElement uiElement, Action customForceLayoutUpdate = null) { //To make sure the items controls render properly //add it to the BusyContent's StackPanel quickly //The BusyIndicator should be open when rendering manifests BusyContentStackPanel.Children.Add(uiElement); //Update the layout if (customForceLayoutUpdate != null) customForceLayoutUpdate(); else BusyContentStackPanel.UpdateLayout(); uiElement.Measure(new Size(double.MaxValue, double.MaxValue)); ImageInline imageInline = null; //Try to create the image inline try { var writableBitmap = new WriteableBitmap((int)uiElement.DesiredSize.Width, (int)uiElement.DesiredSize.Height); writableBitmap.Render(uiElement, null); writableBitmap.Invalidate(); var radImage = new RadBitmap(writableBitmap); var stream = new MemoryStream(); var provider = new PngFormatProvider(); provider.Export(radImage, stream); //Remove the uiElements from the stackpanel so the user does not see it BusyContentStackPanel.Children.Clear(); return new ImageInline(stream); } catch { imageInline = new ImageInline(); //Remove the uiElements from the stackpanel so the user does not see it BusyContentStackPanel.Children.Clear(); } return imageInline; }
private void CreateVideo(IGlymaNode node, ref Paragraph paragraph) { //paragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK)); if (ShowDescriptionIcon) { var videoIcon = new ImageInline(VideoIconStream, new Size(20, 15), "png"); paragraph.Inlines.Add(videoIcon); paragraph.Inlines.Add(new Span(" ")); } else { paragraph.Inlines.Add(new Span("Video:") { FontSize = 12 }); } CreateLink(node.NodeVideo.Link, ref paragraph); if (node.NodeVideo.StartPosition.HasValue || node.NodeVideo.EndPosition.HasValue) { paragraph.Inlines.Add(new Span(FormattingSymbolLayoutBox.LINE_BREAK)); paragraph.Inlines.Add(new Span("Start Time:") { FontSize = 12 }); if (node.NodeVideo.StartPosition.HasValue) { paragraph.Inlines.Add(new Span(string.Format("{0:00}:{1:00}:{2:00}", node.NodeVideo.StartPosition.Value.TotalHours, node.NodeVideo.StartPosition.Value.Minutes, node.NodeVideo.StartPosition.Value.Seconds)) { FontSize = 12 }); paragraph.Inlines.Add(new Span(" ") { FontSize = 12 }); } else { paragraph.Inlines.Add(new Span("00:00:00") { FontSize = 12 }); paragraph.Inlines.Add(new Span(" ") { FontSize = 12 }); } if (node.NodeVideo.EndPosition.HasValue) { paragraph.Inlines.Add(new Span("End Time:") { FontSize = 12 }); paragraph.Inlines.Add(new Span(string.Format("{0:00}:{1:00}:{2:00}", node.NodeVideo.EndPosition.Value.TotalHours, node.NodeVideo.EndPosition.Value.Minutes, node.NodeVideo.EndPosition.Value.Seconds)) { FontSize = 12 }); } } }
private void CreateDocument() { RadDocument document = new RadDocument(); Section section = new Section(); Paragraph paragraph1 = new Paragraph(); Stream stream = Application.GetResourceStream(new Uri(imagePath, UriKind.RelativeOrAbsolute)).Stream; Size size = new Size(236, 50); ImageInline imageInline = new ImageInline(stream, size, "png"); paragraph1.Inlines.Add(imageInline); section.Blocks.Add(paragraph1); Paragraph paragraph2 = new Paragraph(); paragraph2.TextAlignment = Telerik.Windows.Documents.Layout.RadTextAlignment.Center; Span span1 = new Span("Thank you for choosing Telerik"); paragraph2.Inlines.Add(span1); Span span2 = new Span(); span2.Text = " RadRichTextBox!"; span2.FontWeight = FontWeights.Bold; paragraph2.Inlines.Add(span2); section.Blocks.Add(paragraph2); Paragraph paragraph3 = new Paragraph(); Span span3 = new Span("RadRichTextBox"); span3.FontWeight = FontWeights.Bold; paragraph3.Inlines.Add(span3); Span span4 = new Span(" is a control that is able to display and edit rich-text content including formatted text arranged in pages, paragraphs, spans (runs) etc."); paragraph3.Inlines.Add(span4); section.Blocks.Add(paragraph3); Table table = new Table(); table.LayoutMode = TableLayoutMode.AutoFit; table.StyleName = RadDocumentDefaultStyles.DefaultTableGridStyleName; TableRow row1 = new TableRow(); TableCell cell1 = new TableCell(); Paragraph p1 = new Paragraph(); Span s1 = new Span(); s1.Text = "Cell 1"; p1.Inlines.Add(s1); cell1.Blocks.Add(p1); row1.Cells.Add(cell1); TableCell cell2 = new TableCell(); Paragraph p2 = new Paragraph(); Span s2 = new Span(); s2.Text = "Cell 2"; p2.Inlines.Add(s2); cell2.Blocks.Add(p2); row1.Cells.Add(cell2); table.Rows.Add(row1); TableRow row2 = new TableRow(); TableCell cell3 = new TableCell(); cell3.ColumnSpan = 2; Paragraph p3 = new Paragraph(); Span s3 = new Span(); s3.Text = "Cell 3"; p3.Inlines.Add(s3); cell3.Blocks.Add(p3); row2.Cells.Add(cell3); table.Rows.Add(row2); section.Blocks.Add(table); section.Blocks.Add(new Paragraph()); document.Sections.Add(section); this.radRichTextBox.Document = document; }
private void PersonalDetailsSection(RadFlowDocumentEditor editor, Section firstSection) { double tabStopPosition = Unit.InchToDip(6); #region Name & Photo Paragraph nameAndPhotoParagraph = firstSection.Blocks.AddParagraph(); nameAndPhotoParagraph.TabStops = nameAndPhotoParagraph.TabStops.Insert(new TabStop(tabStopPosition, TabStopType.Right)); nameAndPhotoParagraph.StyleId = Heading1StyleId; Run nameRun = nameAndPhotoParagraph.Inlines.AddRun(); this.SetupAndInsertSdt(editor, nameRun, "Enter your name", SdtType.RichText); nameAndPhotoParagraph.Inlines.AddRun("\t"); ImageInline imageInline = new ImageInline(firstSection.Document); imageInline.Image.Size = new Size(200, 200); imageInline.Image.ImageSource = new ImageSource(File.ReadAllBytes(ImagePath), ".png"); nameAndPhotoParagraph.Inlines.Add(imageInline); this.SetupAndInsertSdt(editor, imageInline, null, SdtType.Picture); #endregion #region Role Paragraph roleParagraph = firstSection.Blocks.AddParagraph(); Run roleRun = roleParagraph.Inlines.AddRun(); this.SetupAndInsertSdt(editor, roleRun, "Your desired role?", SdtType.RichText); #endregion #region Phone & Email Paragraph phoneAndEmailParagraph = firstSection.Blocks.AddParagraph(); phoneAndEmailParagraph.TabStops = phoneAndEmailParagraph.TabStops.Insert(new TabStop(tabStopPosition, TabStopType.Right)); Run phoneRun = phoneAndEmailParagraph.Inlines.AddRun(); this.SetupAndInsertSdt(editor, phoneRun, "Phone number", SdtType.RichText); phoneAndEmailParagraph.Inlines.AddRun("\t"); Run emailRun = phoneAndEmailParagraph.Inlines.AddRun(); this.SetupAndInsertSdt(editor, emailRun, "Email address", SdtType.RichText); #endregion #region Website & Location Paragraph websiteAndLocationParagraph = firstSection.Blocks.AddParagraph(); websiteAndLocationParagraph.TabStops = websiteAndLocationParagraph.TabStops.Insert(new TabStop(tabStopPosition, TabStopType.Right)); InlineCollection websiteAndLocationInlines = websiteAndLocationParagraph.Inlines; Run websiteRun = websiteAndLocationInlines.AddRun(); this.SetupAndInsertSdt(editor, websiteRun, "Website", SdtType.RichText); websiteAndLocationInlines.AddRun("\t"); Run locationRun = websiteAndLocationInlines.AddRun(); this.SetupAndInsertSdt(editor, locationRun, "Location", SdtType.RichText); #endregion }
private Header CreateHeader() { RadDocument headerDocument = new RadDocument(); RadDocumentEditor editor = new RadDocumentEditor(headerDocument); using (Stream stream = Application.GetResourceStream(GetResourceUri("Images/Telerik_Logo.jpg")).Stream) { ImageInline image = new ImageInline(stream); editor.InsertInline(image); } editor.ChangeParagraphTextAlignment(RadTextAlignment.Center); Header header = new Header() { Body = headerDocument }; return header; }
private RadDocument CreateDocument() { RadDocument document = new RadDocument(); Section section = new Section(); Paragraph paragraph = new Paragraph(); MemoryStream ms = new MemoryStream(); radChart.ExportToImage(ms, new PngBitmapEncoder()); double imageWidth = radChart.ActualWidth; double imageHeight = radChart.ActualHeight; if (imageWidth > 625) { imageWidth = 625; imageHeight = radChart.ActualHeight * imageWidth / radChart.ActualWidth; } ImageInline image = new ImageInline(ms, new Size(imageWidth, imageHeight), "png"); paragraph.Inlines.Add(image); section.Blocks.Add(paragraph); document.Sections.Add(section); ms.Close(); return document; }
/// <summary> /// Renders an image element. /// </summary> /// <param name="element"> The parsed inline element to render. </param> /// <param name="context"> Persistent state. </param> protected abstract void RenderImage(ImageInline element, IRenderContext context);