/// <summary> /// Sets where the emoticon image is saved so that duplicate emoticons can point to the same image. /// </summary> public void SetInlineImageUri(Emoticon emoticon, Uri inlineUri) { _inlineImageUriTable.Remove(emoticon); _inlineImageUriTable.Add(emoticon, inlineUri); }
/// <summary> /// Sets where the emoticon image is saved so that duplicate emoticons can point to the same image. /// </summary> public void SetInlineImageUri(Emoticon emoticon, Uri inlineUri) { _inlineImageUriTable.Remove(emoticon); _inlineImageUriTable.Add(emoticon, inlineUri); }
/// <summary> /// Gets where the emoticon image is saved so that duplicate emoticons can point to the same image. /// </summary> public Uri GetInlineImageUri(Emoticon emoticon) { Uri inlineImageUri; if (!_inlineImageUriTable.TryGetValue(emoticon, out inlineImageUri)) { inlineImageUri = CreateInlineImage(emoticon); } return inlineImageUri; }
/// <summary> /// Saves the emoticon image to disk and returns the path. Should only be called if the emoticon image has not been saved previously for this blog post. /// </summary> private Uri CreateInlineImage(Emoticon emoticon) { Debug.Assert(_imageEditingContext.ImageList != null && _imageEditingContext.SupportingFileService != null, "ImageEditingContext not initalized yet."); Stream emoticonStream = StreamHelper.AsStream(ImageHelper.GetBitmapBytes(emoticon.Bitmap, ImageFormat.Png)); ISupportingFile sourceFile = _imageEditingContext.SupportingFileService.CreateSupportingFile(emoticon.Id + emoticon.FileExtension, emoticonStream); ImageFileData sourceFileData = new ImageFileData(sourceFile, emoticon.Bitmap.Width, emoticon.Bitmap.Height, ImageFileRelationship.Source); BlogPostImageData imageData = new BlogPostImageData(sourceFileData); if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShadowImageForDrafts)) imageData.InitShadowFile(_imageEditingContext.SupportingFileService); emoticonStream.Seek(0, SeekOrigin.Begin); ISupportingFile inlineFile = _imageEditingContext.SupportingFileService.CreateSupportingFile(emoticon.Id + emoticon.FileExtension, emoticonStream); imageData.InlineImageFile = new ImageFileData(inlineFile, emoticon.Bitmap.Width, emoticon.Bitmap.Height, ImageFileRelationship.Inline); _imageEditingContext.ImageList.AddImage(imageData); SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri); return imageData.InlineImageFile.Uri; }
/// <summary> /// Returns HTML that can be inserted into the canvas to display an emoticon. /// </summary> public string GetHtml(Emoticon emoticon) { if (!CanInsertEmoticonImage) { // If we can't insert images, just return a plain-text emoticon. Debug.Assert(emoticon.AutoReplaceText.Count > 0, "Emoticon is missing autoreplace text."); return emoticon.AutoReplaceText[0]; } Uri inlineImageUri; if (!_inlineImageUriTable.TryGetValue(emoticon, out inlineImageUri)) { inlineImageUri = CreateInlineImage(emoticon); } return String.Format(CultureInfo.InvariantCulture, "<img src=\"{0}\" style=\"border-style: none;\" alt=\"{1}\" class=\"{2} {3}\" />", UrlHelper.SafeToAbsoluteUri(inlineImageUri), HtmlServices.HtmlEncode(emoticon.AltText), Emoticon.CLASS_NAME, emoticon.Id); }
/// <summary> /// Adds the given emoticon as the most recently used. /// </summary> public void AddToRecent(Emoticon emoticon) { // We don't want duplicates, so always attempt to remove the emoticon first. _recentEmoticons.Remove(emoticon); _recentEmoticons.Insert(0, emoticon); if (_recentEmoticons.Count > MAX_RECENT_EMOTICONS) { int numOver = _recentEmoticons.Count - MAX_RECENT_EMOTICONS; _recentEmoticons.RemoveRange(_recentEmoticons.Count - numOver, numOver); } // Save to registry. SaveRecentEmoticons(_recentEmoticons); }