public BlogPostImagePropertiesInfo(BlogPostImageData imageData, ImageDecoratorsList decorators) { _imageData = imageData; ImageFileData sourceFile = imageData.GetImageSourceFile(); Init(sourceFile.Uri, new Size(sourceFile.Width, sourceFile.Height), decorators); }
/// <summary> /// Returns the default margin for images. /// </summary> /// <returns></returns> public MarginStyle GetDefaultImageMargin() { ImageDecoratorsList decoratorsList = LoadDefaultImageDecoratorsList(); IProperties props = decoratorsList.GetImageDecoratorSettings(HtmlMarginDecorator.Id); return(HtmlMarginDecoratorSettings.GetImageMargin(props)); }
/// <summary> /// Return the list of decorators that will essentially leave the image untouched. /// </summary> public ImageDecoratorsList LoadBlankLocalImageDecoratorsList() { string[] defaultDecoratorIds = new string[] { BrightnessDecorator.Id, CropDecorator.Id, HtmlAlignDecorator.Id, HtmlAltTextDecorator.Id, HtmlImageResizeDecorator.Id, HtmlImageTargetDecorator.Id, HtmlMarginDecorator.Id, NoBorderDecorator.Id, NoRecolorDecorator.Id, NoSharpenDecorator.Id, NoBlurDecorator.Id, NoEmbossDecorator.Id, TiltDecorator.Id, WatermarkDecorator.Id }; ImageDecoratorsList decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag()); foreach (string decoratorId in defaultDecoratorIds) { decoratorsList.AddDecorator(decoratorId); } return(decoratorsList); }
public void SaveAsDefault(ImagePropertiesInfo imageInfo) { ImageDecoratorsList decorators = imageInfo.ImageDecorators; //delete the existing image settings DeleteImageSettings(_contextId); using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, true)) { //loop over the image decorators and save the settings of any decorators that are defaultable. StringBuilder sb = new StringBuilder(); foreach (string decoratorId in decorators.GetImageDecoratorIds()) { ImageDecorator decorator = decorators.GetImageDecorator(decoratorId); if (decorator.IsDefaultable) { if (sb.Length > 0) { sb.Append(","); } sb.Append(decorator.Id); using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId)) { PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings); IProperties decoratorCurrentSettings = decorators.GetImageDecoratorSettings(decoratorId); CopySettings(decoratorCurrentSettings, settings); ImageDecoratorEditorContext editorContext = new ImageDecoratorEditorContextImpl(decoratorCurrentSettings, null, imageInfo, new NoOpUndoUnitFactory(), _decoratorsManager.CommandManager); decorator.ApplyCustomizeDefaultSettingsHook(editorContext, settings); } } } contextImageSettings.SetString(ImageDecoratorsListKey, sb.ToString()); } }
/// <summary> /// Load the default image decorators for the current image context. /// </summary> /// <returns></returns> public ImageDecoratorsList LoadDefaultImageDecoratorsList() { using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, false)) { ImageDecoratorsList decoratorsList; if (contextImageSettings == null) { decoratorsList = GetInitialLocalImageDecoratorsList(); } else { decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag(), false); string[] decoratorIds = contextImageSettings.GetString(ImageDecoratorsListKey, "").Split(','); foreach (string decoratorId in decoratorIds) { ImageDecorator imageDecorator = _decoratorsManager.GetImageDecorator(decoratorId); if (imageDecorator != null) //can be null if the decorator is no longer valid { decoratorsList.AddDecorator(imageDecorator); using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId)) { PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings); CopySettings(settings, decoratorsList.GetImageDecoratorSettings(decoratorId)); } } } } //now add the implicit decorators IFF they aren't already in the list decoratorsList.MergeDecorators(GetImplicitLocalImageDecorators()); return(decoratorsList); } }
private ImageFilterDecoratorAdapter(ImagePropertiesInfo imageInfo, ImageEmbedType embedType, ImageDecoratorInvocationSource invocationSource, IEditorOptions editorOptions) { _decoratorsList = imageInfo.ImageDecorators; _imageInfo = imageInfo; _embedType = embedType; _invocationSource = invocationSource; _editorOptions = editorOptions; }
private ImageFilterDecoratorAdapter(ImagePropertiesInfo imageInfo, ImageEmbedType embedType, ImageDecoratorInvocationSource invocationSource, IEditorOptions editorOptions) { _decoratorsList = imageInfo.ImageDecorators; _imageInfo = imageInfo; _embedType = embedType; _invocationSource = invocationSource; _editorOptions = editorOptions; }
/// <summary> /// Returns the default image size for inline images. /// </summary> /// <returns></returns> public Size GetDefaultInlineImageSize() { ImageDecoratorsList decoratorsList = LoadDefaultImageDecoratorsList(); IProperties props = decoratorsList.GetImageDecoratorSettings(HtmlImageResizeDecorator.Id); Size imgSize = HtmlImageResizeDecoratorSettings.GetDefaultImageSize(props); return(imgSize); }
private void imageResetCommand_Execute(object sender, EventArgs e) { // get the default settings DefaultImageSettings defaultImageSettings = new DefaultImageSettings(_imageEditingContext.CurrentAccountId, _imageEditingContext.DecoratorsManager); ImageDecoratorsList defaultDecoratorsList = defaultImageSettings.LoadDefaultImageDecoratorsList(); // reset them ImagePropertiesInfo.ResetImageSettings(defaultDecoratorsList); // apply decorations ApplyImageDecorations(ImagePropertyType.Decorators, ImageDecoratorInvocationSource.Reset); }
/// <summary> /// Resets the image decorators back to their defaults. /// </summary> public void ResetImageSettings(ImageDecoratorsList defaultDecorators) { //preserve the HTML rotation setting RotateFlipType oldRotation = ImageRotation; //reset the image decorators ImageDecorators = defaultDecorators; targetDecoratorSettings = null; _inlineImageSettings = null; //restore the image rotation setting. InlineImageSettings.Rotation = oldRotation; }
/// <summary> /// Return the list of decorators to use if there are no saved decorators for the current context. /// </summary> /// <returns></returns> private ImageDecoratorsList GetInitialLocalImageDecoratorsList() { string[] defaultDecoratorIds = new string[] { CropDecorator.Id, HtmlImageResizeDecorator.Id, HtmlImageTargetDecorator.Id, HtmlMarginDecorator.Id, HtmlAlignDecorator.Id, //DropShadowBorderDecorator.Id, NoRecolorDecorator.Id, NoSharpenDecorator.Id, NoBlurDecorator.Id, NoEmbossDecorator.Id }; ImageDecoratorsList decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag()); foreach (string decoratorId in defaultDecoratorIds) { decoratorsList.AddDecorator(decoratorId); } return(decoratorsList); }
internal void SynchronizeImageDecorators() { ArrayList decoratorsList = new ArrayList(); foreach (string decoratorId in ImageDecoratorsList.GetImageDecoratorIds()) { ImageDecorator decorator = _decoratorsManager.GetImageDecorator(decoratorId); if (!decorator.IsHidden) { decoratorsList.Add(decorator); } } bool needsReload = false; if (decoratorsList.Count != listViewDecoratorsTable.Items.Count) { needsReload = true; } else { for (int i = 0; i < decoratorsList.Count && !needsReload; i++) { ImageDecorator decorator = (ImageDecorator)decoratorsList[i]; if (listViewDecoratorsTable.Items[i].Tag != decorator) { needsReload = true; } } } if (needsReload) { ReloadImageDecorators(); } }
/// <summary> /// Return the list of decorators to use if there are no saved decorators for the current context. /// </summary> /// <returns></returns> private ImageDecoratorsList GetInitialLocalImageDecoratorsList() { string[] defaultDecoratorIds = new string[]{ CropDecorator.Id, HtmlImageResizeDecorator.Id, HtmlImageTargetDecorator.Id, HtmlMarginDecorator.Id, HtmlAlignDecorator.Id, DropShadowBorderDecorator.Id, NoRecolorDecorator.Id, NoSharpenDecorator.Id, NoBlurDecorator.Id, NoEmbossDecorator.Id}; ImageDecoratorsList decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag()); foreach (string decoratorId in defaultDecoratorIds) decoratorsList.AddDecorator(decoratorId); return decoratorsList; }
/// <summary> /// Return the list of decorators that will essentially leave the image untouched. /// </summary> public ImageDecoratorsList LoadBlankLocalImageDecoratorsList() { string[] defaultDecoratorIds = new string[] { BrightnessDecorator.Id, CropDecorator.Id, HtmlAlignDecorator.Id, HtmlAltTextDecorator.Id, HtmlImageResizeDecorator.Id, HtmlImageTargetDecorator.Id, HtmlMarginDecorator.Id, NoBorderDecorator.Id, NoRecolorDecorator.Id, NoSharpenDecorator.Id, NoBlurDecorator.Id, NoEmbossDecorator.Id, TiltDecorator.Id, WatermarkDecorator.Id }; ImageDecoratorsList decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag()); foreach (string decoratorId in defaultDecoratorIds) decoratorsList.AddDecorator(decoratorId); return decoratorsList; }
/// <summary> /// Load the default image decorators for the current image context. /// </summary> /// <returns></returns> public ImageDecoratorsList LoadDefaultImageDecoratorsList() { using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, false)) { ImageDecoratorsList decoratorsList; if (contextImageSettings == null) { decoratorsList = GetInitialLocalImageDecoratorsList(); } else { decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag(), false); string[] decoratorIds = contextImageSettings.GetString(ImageDecoratorsListKey, "").Split(','); foreach (string decoratorId in decoratorIds) { ImageDecorator imageDecorator = _decoratorsManager.GetImageDecorator(decoratorId); if (imageDecorator != null) //can be null if the decorator is no longer valid { decoratorsList.AddDecorator(imageDecorator); using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId)) { PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings); CopySettings(settings, decoratorsList.GetImageDecoratorSettings(decoratorId)); } } } } //now add the implicit decorators IFF they aren't already in the list decoratorsList.MergeDecorators(GetImplicitLocalImageDecorators()); return decoratorsList; } }
protected void Init(Uri sourceUri, Size size, ImageDecoratorsList decorators) { _imageSourceUri = sourceUri; _size = size; ImageDecorators = decorators; }
public ImagePropertiesInfo(Uri sourceUri, Size size, ImageDecoratorsList decorators) { Init(sourceUri, new Size(size.Width, size.Height), decorators); }
private static List<NewImageInfo> ScanImages(IBlogPostHtmlEditor currentEditor, IEditorAccount editorAccount, ContentEditor editor, bool useDefaultTargetSettings) { List<NewImageInfo> newImages = new List<NewImageInfo>(); ApplicationPerformance.ClearEvent("InsertImage"); ApplicationPerformance.StartEvent("InsertImage"); using (new WaitCursor()) { IHTMLElement2 postBodyElement = (IHTMLElement2)((BlogPostHtmlEditorControl)currentEditor).PostBodyElement; if (postBodyElement != null) { foreach (IHTMLElement imgElement in postBodyElement.getElementsByTagName("img")) { string imageSrc = imgElement.getAttribute("srcDelay", 2) as string; if (string.IsNullOrEmpty(imageSrc)) { imageSrc = imgElement.getAttribute("src", 2) as string; } // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. "wlCopySrcUrl" is inserted while copy/pasting within canvas. bool copyDecoratorSettings = false; string attributeCopySrcUrl = imgElement.getAttribute("wlCopySrcUrl", 2) as string; if (!string.IsNullOrEmpty(attributeCopySrcUrl)) { copyDecoratorSettings = true; imgElement.removeAttribute("wlCopySrcUrl", 0); } // Check if we need to apply default values for image decorators bool applyDefaultDecorator = true; string attributeNoDefaultDecorator = imgElement.getAttribute("wlNoDefaultDecorator", 2) as string; if (!string.IsNullOrEmpty(attributeNoDefaultDecorator) && string.Compare(attributeNoDefaultDecorator, "TRUE", StringComparison.OrdinalIgnoreCase) == 0) { applyDefaultDecorator = false; imgElement.removeAttribute("wlNoDefaultDecorator", 0); } string applyDefaultMargins = imgElement.getAttribute("wlApplyDefaultMargins", 2) as string; if (!String.IsNullOrEmpty(applyDefaultMargins)) { DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); MarginStyle defaultMargin = defaultImageSettings.GetDefaultImageMargin(); // Now apply it to the image imgElement.style.marginTop = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Top); imgElement.style.marginLeft = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Left); imgElement.style.marginBottom = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Bottom); imgElement.style.marginRight = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Right); imgElement.removeAttribute("wlApplyDefaultMargins", 0); } if ((UrlHelper.IsFileUrl(imageSrc) || IsFullPath(imageSrc)) && !ContentSourceManager.IsSmartContent(imgElement)) { Uri imageSrcUri = new Uri(imageSrc); try { BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, imageSrcUri); Emoticon emoticon = EmoticonsManager.GetEmoticon(imgElement); if (imageData == null && emoticon != null) { // This is usually an emoticon copy/paste and needs to be cleaned up. Uri inlineImageUri = editor.EmoticonsManager.GetInlineImageUri(emoticon); imgElement.setAttribute("src", UrlHelper.SafeToAbsoluteUri(inlineImageUri), 0); } else if (imageData == null) { if (!File.Exists(imageSrcUri.LocalPath)) throw new FileNotFoundException(imageSrcUri.LocalPath); // WinLive 188841: Manually attach the behavior so that the image cannot be selected or resized while its loading. DisabledImageElementBehavior disabledImageBehavior = new DisabledImageElementBehavior(editor.IHtmlEditorComponentContext); disabledImageBehavior.AttachToElement(imgElement); Size sourceImageSize = ImageUtils.GetImageSize(imageSrcUri.LocalPath); ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, sourceImageSize, new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag())); DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); // Make sure this is set because some imageInfo properties depend on it. imageInfo.ImgElement = imgElement; bool isMetafile = ImageHelper2.IsMetafile(imageSrcUri.LocalPath); ImageClassification imgClass = ImageHelper2.Classify(imageSrcUri.LocalPath); if (!isMetafile && ((imgClass & ImageClassification.AnimatedGif) != ImageClassification.AnimatedGif)) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. if (copyDecoratorSettings) { // Try to look up the original copied source image. BlogPostImageData imageDataOriginal = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, new Uri(attributeCopySrcUrl)); if (imageDataOriginal != null && imageDataOriginal.GetImageSourceFile() != null) { // We have the original image reference, so lets make a clone of it. BlogPostSettingsBag originalBag = (BlogPostSettingsBag)imageDataOriginal.ImageDecoratorSettings.Clone(); ImageDecoratorsList originalDecoratorsList = new ImageDecoratorsList(editor.DecoratorsManager, originalBag); ImageFileData originalImageFileData = imageDataOriginal.GetImageSourceFile(); Size originalImageSize = new Size(originalImageFileData.Width, originalImageFileData.Height); imageInfo = new ImagePropertiesInfo(originalImageFileData.Uri, originalImageSize, originalDecoratorsList); } else { // There are probably decorators applied to the image, but in a different editor so we can't access them. // We probably don't want to apply any decorators to this image, so apply blank decorators and load the // image as full size so it looks like it did before. imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else if (applyDefaultDecorator) { imageInfo.ImageDecorators = defaultImageSettings.LoadDefaultImageDecoratorsList(); if ((imgClass & ImageClassification.TransparentGif) == ImageClassification.TransparentGif) imageInfo.ImageDecorators.AddDecorator(NoBorderDecorator.Id); } else { // Don't use default values for decorators imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else { ImageDecoratorsList decorators = new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag()); decorators.AddDecorator(editor.DecoratorsManager.GetDefaultRemoteImageDecorators()); imageInfo.ImageDecorators = decorators; } imageInfo.ImgElement = imgElement; imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; //discover the "natural" target settings from the DOM string linkTargetUrl = imageInfo.LinkTargetUrl; if (linkTargetUrl == imageSrc) { imageInfo.LinkTarget = LinkTargetType.IMAGE; } else if (!String.IsNullOrEmpty(linkTargetUrl) && !UrlHelper.IsFileUrl(linkTargetUrl)) { imageInfo.LinkTarget = LinkTargetType.URL; } else { imageInfo.LinkTarget = LinkTargetType.NONE; } if (useDefaultTargetSettings) { if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs) && imageInfo.DefaultLinkTarget == LinkTargetType.IMAGE) imageInfo.DefaultLinkTarget = LinkTargetType.NONE; if (imageInfo.LinkTarget == LinkTargetType.NONE) imageInfo.LinkTarget = imageInfo.DefaultLinkTarget; if (imageInfo.DefaultLinkOptions.ShowInNewWindow) imageInfo.LinkOptions.ShowInNewWindow = true; imageInfo.LinkOptions.UseImageViewer = imageInfo.DefaultLinkOptions.UseImageViewer; imageInfo.LinkOptions.ImageViewerGroupName = imageInfo.DefaultLinkOptions.ImageViewerGroupName; } Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize(); Size initialSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, sourceImageSize); // add to list of new images newImages.Add(new NewImageInfo(imageInfo, imgElement, initialSize, disabledImageBehavior)); } else { // When switching blogs, try to adapt image viewer settings according to the blog settings. ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, ImageUtils.GetImageSize(imageSrcUri.LocalPath), new ImageDecoratorsList(editor.DecoratorsManager, imageData.ImageDecoratorSettings)); imageInfo.ImgElement = imgElement; // Make sure the new crop and tilt decorators get loaded imageInfo.ImageDecorators.MergeDecorators(DefaultImageSettings.GetImplicitLocalImageDecorators()); string viewer = imageInfo.DhtmlImageViewer; if (viewer != editorAccount.EditorOptions.DhtmlImageViewer) { imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; imageInfo.LinkOptions = imageInfo.DefaultLinkOptions; } // If the image is an emoticon, update the EmoticonsManager with the image's uri so that duplicate emoticons can point to the same file. if (emoticon != null) editor.EmoticonsManager.SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri); } } catch (ArgumentException e) { Trace.WriteLine("Could not initialize image: " + imageSrc); Trace.WriteLine(e.ToString()); } catch (DirectoryNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (FileNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (IOException e) { Debug.WriteLine("Image file cannot be read: " + imageSrc + " " + e); DisplayMessage.Show(MessageId.FileInUse, imageSrc); } } } } } return newImages; }
public static ImagePropertiesInfo GetImagePropertiesInfo(IHTMLImgElement imgElement, IBlogPostImageEditingContext editorContext) { IHTMLElement imgHtmlElement = (IHTMLElement)imgElement; string imgSrc = imgHtmlElement.getAttribute("src", 2) as string; BlogPostImageData imageData = null; try { imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, new Uri(imgSrc)); } catch (UriFormatException) { //this URI is probably relative web URL, so extract the image src letting the //DOM fill in the full URL for us based on the base URL. imgSrc = imgHtmlElement.getAttribute("src", 0) as string; } ImagePropertiesInfo info; if (imageData != null && imageData.GetImageSourceFile() != null) { //clone the image data to the sidebar doesn't change it (required for preserving image undo/redo state) imageData = (BlogPostImageData)imageData.Clone(); //this is an attached local image info = new BlogPostImagePropertiesInfo(imageData, new ImageDecoratorsList(editorContext.DecoratorsManager, imageData.ImageDecoratorSettings)); info.ImgElement = imgHtmlElement; } else { //this is not an attached local image, so treat as a web image ImageDecoratorsList remoteImageDecoratorsList = new ImageDecoratorsList(editorContext.DecoratorsManager, new BlogPostSettingsBag()); remoteImageDecoratorsList.AddDecorator(editorContext.DecoratorsManager.GetDefaultRemoteImageDecorators()); //The source image size is unknown, so calculate the actual image size by removing //the size attributes, checking the size, and then placing the size attributes back string oldHeight = imgHtmlElement.getAttribute("height", 2) as string; string oldWidth = imgHtmlElement.getAttribute("width", 2) as string; imgHtmlElement.removeAttribute("width", 0); imgHtmlElement.removeAttribute("height", 0); int width = imgElement.width; int height = imgElement.height; if (!String.IsNullOrEmpty(oldHeight)) { imgHtmlElement.setAttribute("height", oldHeight, 0); } if (!String.IsNullOrEmpty(oldWidth)) { imgHtmlElement.setAttribute("width", oldWidth, 0); } info = new ImagePropertiesInfo(new Uri(imgSrc), new Size(width, height), remoteImageDecoratorsList); info.ImgElement = imgHtmlElement; // Sets the correct inline image size and image size name for the remote image. if (!String.IsNullOrEmpty(oldWidth) && !String.IsNullOrEmpty(oldHeight)) { int inlineWidth, inlineHeight; if (Int32.TryParse(oldWidth, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineWidth) && Int32.TryParse(oldHeight, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineHeight)) { info.InlineImageSize = new Size(inlineWidth, inlineHeight); } } // Sets the correct border style for the remote image. if (new HtmlBorderDecoratorSettings(imgHtmlElement).InheritBorder) { if (!info.ImageDecorators.ContainsDecorator(HtmlBorderDecorator.Id)) { info.ImageDecorators.AddDecorator(HtmlBorderDecorator.Id); } } else if (new NoBorderDecoratorSettings(imgHtmlElement).NoBorder) { if (!info.ImageDecorators.ContainsDecorator(NoBorderDecorator.Id)) { info.ImageDecorators.AddDecorator(NoBorderDecorator.Id); } } } //transfer image data properties if (imageData != null) { info.UploadSettings = imageData.UploadInfo.Settings; info.UploadServiceId = imageData.UploadInfo.ImageServiceId; if (info.UploadServiceId == null) { info.UploadServiceId = editorContext.ImageServiceId; } } return(info); }
public static ImagePropertiesInfo GetImagePropertiesInfo(IHTMLImgElement imgElement, IBlogPostImageEditingContext editorContext) { IHTMLElement imgHtmlElement = (IHTMLElement)imgElement; string imgSrc = imgHtmlElement.getAttribute("src", 2) as string; BlogPostImageData imageData = null; try { imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editorContext.ImageList, new Uri(imgSrc)); } catch (UriFormatException) { //this URI is probably relative web URL, so extract the image src letting the //DOM fill in the full URL for us based on the base URL. imgSrc = imgHtmlElement.getAttribute("src", 0) as string; } ImagePropertiesInfo info; if (imageData != null && imageData.GetImageSourceFile() != null) { //clone the image data to the sidebar doesn't change it (required for preserving image undo/redo state) imageData = (BlogPostImageData)imageData.Clone(); //this is an attached local image info = new BlogPostImagePropertiesInfo(imageData, new ImageDecoratorsList(editorContext.DecoratorsManager, imageData.ImageDecoratorSettings)); info.ImgElement = imgHtmlElement; } else { //this is not an attached local image, so treat as a web image ImageDecoratorsList remoteImageDecoratorsList = new ImageDecoratorsList(editorContext.DecoratorsManager, new BlogPostSettingsBag()); remoteImageDecoratorsList.AddDecorator(editorContext.DecoratorsManager.GetDefaultRemoteImageDecorators()); //The source image size is unknown, so calculate the actual image size by removing //the size attributes, checking the size, and then placing the size attributes back string oldHeight = imgHtmlElement.getAttribute("height", 2) as string; string oldWidth = imgHtmlElement.getAttribute("width", 2) as string; imgHtmlElement.removeAttribute("width", 0); imgHtmlElement.removeAttribute("height", 0); int width = imgElement.width; int height = imgElement.height; if (!String.IsNullOrEmpty(oldHeight)) imgHtmlElement.setAttribute("height", oldHeight, 0); if (!String.IsNullOrEmpty(oldWidth)) imgHtmlElement.setAttribute("width", oldWidth, 0); Uri infoUri; if (Uri.TryCreate(imgSrc, UriKind.Absolute, out infoUri)) { info = new ImagePropertiesInfo(infoUri, new Size(width, height), remoteImageDecoratorsList); } else { info = new ImagePropertiesInfo(new Uri("http://www.example.com"), new Size(width, height), remoteImageDecoratorsList); } info.ImgElement = imgHtmlElement; // Sets the correct inline image size and image size name for the remote image. if (!String.IsNullOrEmpty(oldWidth) && !String.IsNullOrEmpty(oldHeight)) { int inlineWidth, inlineHeight; if (Int32.TryParse(oldWidth, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineWidth) && Int32.TryParse(oldHeight, NumberStyles.Integer, CultureInfo.InvariantCulture, out inlineHeight)) { info.InlineImageSize = new Size(inlineWidth, inlineHeight); } } // Sets the correct border style for the remote image. if (new HtmlBorderDecoratorSettings(imgHtmlElement).InheritBorder) { if (!info.ImageDecorators.ContainsDecorator(HtmlBorderDecorator.Id)) info.ImageDecorators.AddDecorator(HtmlBorderDecorator.Id); } else if (new NoBorderDecoratorSettings(imgHtmlElement).NoBorder) { if (!info.ImageDecorators.ContainsDecorator(NoBorderDecorator.Id)) info.ImageDecorators.AddDecorator(NoBorderDecorator.Id); } } //transfer image data properties if (imageData != null) { info.UploadSettings = imageData.UploadInfo.Settings; info.UploadServiceId = imageData.UploadInfo.ImageServiceId; if (info.UploadServiceId == null) { info.UploadServiceId = editorContext.ImageServiceId; } } return info; }
private static List <NewImageInfo> ScanImages(IBlogPostHtmlEditor currentEditor, IEditorAccount editorAccount, ContentEditor editor, bool useDefaultTargetSettings) { List <NewImageInfo> newImages = new List <NewImageInfo>(); ApplicationPerformance.ClearEvent("InsertImage"); ApplicationPerformance.StartEvent("InsertImage"); using (new WaitCursor()) { IHTMLElement2 postBodyElement = (IHTMLElement2)((BlogPostHtmlEditorControl)currentEditor).PostBodyElement; if (postBodyElement != null) { foreach (IHTMLElement imgElement in postBodyElement.getElementsByTagName("img")) { string imageSrc = imgElement.getAttribute("srcDelay", 2) as string; if (string.IsNullOrEmpty(imageSrc)) { imageSrc = imgElement.getAttribute("src", 2) as string; } // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. "wlCopySrcUrl" is inserted while copy/pasting within canvas. bool copyDecoratorSettings = false; string attributeCopySrcUrl = imgElement.getAttribute("wlCopySrcUrl", 2) as string; if (!string.IsNullOrEmpty(attributeCopySrcUrl)) { copyDecoratorSettings = true; imgElement.removeAttribute("wlCopySrcUrl", 0); } // Check if we need to apply default values for image decorators bool applyDefaultDecorator = true; string attributeNoDefaultDecorator = imgElement.getAttribute("wlNoDefaultDecorator", 2) as string; if (!string.IsNullOrEmpty(attributeNoDefaultDecorator) && string.Compare(attributeNoDefaultDecorator, "TRUE", StringComparison.OrdinalIgnoreCase) == 0) { applyDefaultDecorator = false; imgElement.removeAttribute("wlNoDefaultDecorator", 0); } string applyDefaultMargins = imgElement.getAttribute("wlApplyDefaultMargins", 2) as string; if (!String.IsNullOrEmpty(applyDefaultMargins)) { DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); MarginStyle defaultMargin = defaultImageSettings.GetDefaultImageMargin(); // Now apply it to the image imgElement.style.marginTop = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Top); imgElement.style.marginLeft = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Left); imgElement.style.marginBottom = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Bottom); imgElement.style.marginRight = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Right); imgElement.removeAttribute("wlApplyDefaultMargins", 0); } if ((UrlHelper.IsFileUrl(imageSrc) || IsFullPath(imageSrc)) && !ContentSourceManager.IsSmartContent(imgElement)) { Uri imageSrcUri = new Uri(imageSrc); try { BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, imageSrcUri); Emoticon emoticon = EmoticonsManager.GetEmoticon(imgElement); if (imageData == null && emoticon != null) { // This is usually an emoticon copy/paste and needs to be cleaned up. Uri inlineImageUri = editor.EmoticonsManager.GetInlineImageUri(emoticon); imgElement.setAttribute("src", UrlHelper.SafeToAbsoluteUri(inlineImageUri), 0); } else if (imageData == null) { if (!File.Exists(imageSrcUri.LocalPath)) { throw new FileNotFoundException(imageSrcUri.LocalPath); } // WinLive 188841: Manually attach the behavior so that the image cannot be selected or resized while its loading. DisabledImageElementBehavior disabledImageBehavior = new DisabledImageElementBehavior(editor.IHtmlEditorComponentContext); disabledImageBehavior.AttachToElement(imgElement); Size sourceImageSize = ImageUtils.GetImageSize(imageSrcUri.LocalPath); ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, sourceImageSize, new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag())); DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager); // Make sure this is set because some imageInfo properties depend on it. imageInfo.ImgElement = imgElement; bool isMetafile = ImageHelper2.IsMetafile(imageSrcUri.LocalPath); ImageClassification imgClass = ImageHelper2.Classify(imageSrcUri.LocalPath); if (!isMetafile && ((imgClass & ImageClassification.AnimatedGif) != ImageClassification.AnimatedGif)) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. if (copyDecoratorSettings) { // Try to look up the original copied source image. BlogPostImageData imageDataOriginal = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, new Uri(attributeCopySrcUrl)); if (imageDataOriginal != null && imageDataOriginal.GetImageSourceFile() != null) { // We have the original image reference, so lets make a clone of it. BlogPostSettingsBag originalBag = (BlogPostSettingsBag)imageDataOriginal.ImageDecoratorSettings.Clone(); ImageDecoratorsList originalDecoratorsList = new ImageDecoratorsList(editor.DecoratorsManager, originalBag); ImageFileData originalImageFileData = imageDataOriginal.GetImageSourceFile(); Size originalImageSize = new Size(originalImageFileData.Width, originalImageFileData.Height); imageInfo = new ImagePropertiesInfo(originalImageFileData.Uri, originalImageSize, originalDecoratorsList); } else { // There are probably decorators applied to the image, but in a different editor so we can't access them. // We probably don't want to apply any decorators to this image, so apply blank decorators and load the // image as full size so it looks like it did before. imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else if (applyDefaultDecorator) { imageInfo.ImageDecorators = defaultImageSettings.LoadDefaultImageDecoratorsList(); if ((imgClass & ImageClassification.TransparentGif) == ImageClassification.TransparentGif) { imageInfo.ImageDecorators.AddDecorator(NoBorderDecorator.Id); } } else { // Don't use default values for decorators imageInfo.ImageDecorators = defaultImageSettings.LoadBlankLocalImageDecoratorsList(); imageInfo.InlineImageSizeName = ImageSizeName.Full; } } else { ImageDecoratorsList decorators = new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag()); decorators.AddDecorator(editor.DecoratorsManager.GetDefaultRemoteImageDecorators()); imageInfo.ImageDecorators = decorators; } imageInfo.ImgElement = imgElement; imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; //discover the "natural" target settings from the DOM string linkTargetUrl = imageInfo.LinkTargetUrl; if (linkTargetUrl == imageSrc) { imageInfo.LinkTarget = LinkTargetType.IMAGE; } else if (!String.IsNullOrEmpty(linkTargetUrl) && !UrlHelper.IsFileUrl(linkTargetUrl)) { imageInfo.LinkTarget = LinkTargetType.URL; } else { imageInfo.LinkTarget = LinkTargetType.NONE; } if (useDefaultTargetSettings) { if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs) && imageInfo.DefaultLinkTarget == LinkTargetType.IMAGE) { imageInfo.DefaultLinkTarget = LinkTargetType.NONE; } if (imageInfo.LinkTarget == LinkTargetType.NONE) { imageInfo.LinkTarget = imageInfo.DefaultLinkTarget; } if (imageInfo.DefaultLinkOptions.ShowInNewWindow) { imageInfo.LinkOptions.ShowInNewWindow = true; } imageInfo.LinkOptions.UseImageViewer = imageInfo.DefaultLinkOptions.UseImageViewer; imageInfo.LinkOptions.ImageViewerGroupName = imageInfo.DefaultLinkOptions.ImageViewerGroupName; } Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize(); Size initialSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, sourceImageSize); // add to list of new images newImages.Add(new NewImageInfo(imageInfo, imgElement, initialSize, disabledImageBehavior)); } else { // When switching blogs, try to adapt image viewer settings according to the blog settings. ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, ImageUtils.GetImageSize(imageSrcUri.LocalPath), new ImageDecoratorsList(editor.DecoratorsManager, imageData.ImageDecoratorSettings)); imageInfo.ImgElement = imgElement; // Make sure the new crop and tilt decorators get loaded imageInfo.ImageDecorators.MergeDecorators(DefaultImageSettings.GetImplicitLocalImageDecorators()); string viewer = imageInfo.DhtmlImageViewer; if (viewer != editorAccount.EditorOptions.DhtmlImageViewer) { imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer; imageInfo.LinkOptions = imageInfo.DefaultLinkOptions; } // If the image is an emoticon, update the EmoticonsManager with the image's uri so that duplicate emoticons can point to the same file. if (emoticon != null) { editor.EmoticonsManager.SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri); } } } catch (ArgumentException e) { Trace.WriteLine("Could not initialize image: " + imageSrc); Trace.WriteLine(e.ToString()); } catch (DirectoryNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (FileNotFoundException) { Debug.WriteLine("Image file does not exist: " + imageSrc); } catch (IOException e) { Debug.WriteLine("Image file cannot be read: " + imageSrc + " " + e); DisplayMessage.Show(MessageId.FileInUse, imageSrc); } } } } } return(newImages); }