diff --git a/.gitignore b/.gitignore index a9ddde4..8fac563 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ .vs/* bin/* -obj/* \ No newline at end of file +obj/* +publish/* +*.user \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c4dbf22 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) Microsoft Corporation + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/PictureViewer.xaml.cs b/PictureViewer.xaml.cs index 05efbae..7e505ba 100644 --- a/PictureViewer.xaml.cs +++ b/PictureViewer.xaml.cs @@ -26,8 +26,12 @@ namespace WordPictureViewer /// public partial class PictureViewer : Window { + #region Private Members private int _scale = 100; private int _scaleStep = 9; + #endregion + + #region Constructor public PictureViewer(Bitmap bitmap) { InitializeComponent(); @@ -37,13 +41,12 @@ public PictureViewer(Bitmap bitmap) WindowStyle = WindowStyle.None; AllowsTransparency = true; + // Init image size double screenW = SystemParameters.PrimaryScreenWidth; - double screenH = SystemParameters.PrimaryScreenHeight - 35; - + double screenH = SystemParameters.PrimaryScreenHeight; double initW = bitmap.Width; double initH = bitmap.Height; double ratio = (double)bitmap.Width / bitmap.Height; - if(initW > screenW) { initW= screenW; @@ -58,6 +61,7 @@ public PictureViewer(Bitmap bitmap) initH *= 0.8; UIImage.Width = initW; UIImage.Height = initH; + // Set image source using (MemoryStream ms = new MemoryStream()) { bitmap.Save(ms, ImageFormat.Png); @@ -68,24 +72,26 @@ public PictureViewer(Bitmap bitmap) bi.EndInit(); UIImage.Source = bi; } - + // Mouse wheel event MouseWheel += PictureViewer_MouseWheel; } + #endregion + #region Private Methods private void PictureViewer_MouseWheel(object sender, MouseWheelEventArgs e) { - if(e.Delta > 0) + if(e.Delta > 0) // zoom in { if(_scaleStep < 0)_scaleStep = -_scaleStep; else _scaleStep++; } - else + else // zoom out { if (_scaleStep > 0) _scaleStep = -_scaleStep; else if(_scale + _scaleStep >= 99) _scaleStep++; } - if (_scale + _scaleStep < 100) return; + // smooth scale animation DoubleAnimation aniScale = new DoubleAnimation() { Duration = TimeSpan.FromMilliseconds(250) }; _scale += _scaleStep; aniScale.To = (double)_scale / 100; @@ -107,5 +113,6 @@ private void UICloseBtn_Click(object sender, RoutedEventArgs e) { Close(); } + #endregion } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..9823c75 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# WordPictureViewer (Word 图片预览) + +本项目是一款用于以大图方式浏览 Word 文档中图片的 Word VSTO 外接程序。 + +启用后,双击文档中的图片即可预览。 + +*This project is a Word VSTO add-in program used to browse images in Word documents in a large image way.* + +*Once enabled, double-click the image in the document to preview it.* + +![example_01](https://github.com/theyangfan/WordPictureViewer/blob/main/example_01.png) + +![example_02](https://github.com/theyangfan/WordPictureViewer/blob/main/example_02.png) diff --git a/Ribbon.Designer.cs b/Ribbon.Designer.cs index bb4de26..315c721 100644 --- a/Ribbon.Designer.cs +++ b/Ribbon.Designer.cs @@ -11,6 +11,16 @@ public Ribbon() : base(Globals.Factory.GetRibbonFactory()) { InitializeComponent(); + if (System.Globalization.CultureInfo.CurrentCulture.NativeName.StartsWith("中文")) + { + tab1.Label = "图片预览"; + UIEnable.Label = "启用"; + } + else + { + tab1.Label = "PicViewer"; + UIEnable.Label = "Enable"; + } } /// @@ -47,6 +57,7 @@ private void InitializeComponent() this.tab1.Groups.Add(this.group1); this.tab1.Label = "图片预览"; this.tab1.Name = "tab1"; + this.tab1.Tag = ""; // // group1 // @@ -75,10 +86,9 @@ private void InitializeComponent() } #endregion - - internal Microsoft.Office.Tools.Ribbon.RibbonTab tab1; internal Microsoft.Office.Tools.Ribbon.RibbonGroup group1; internal Microsoft.Office.Tools.Ribbon.RibbonCheckBox UIEnable; + internal Microsoft.Office.Tools.Ribbon.RibbonTab tab1; } partial class ThisRibbonCollection diff --git a/Ribbon.cs b/Ribbon.cs index 0237db5..1ce704a 100644 --- a/Ribbon.cs +++ b/Ribbon.cs @@ -16,7 +16,7 @@ public bool IsEnable private void Ribbon_Load(object sender, RibbonUIEventArgs e) { - + } } } diff --git a/ThisAddIn.cs b/ThisAddIn.cs index 2fde978..84b8eb3 100644 --- a/ThisAddIn.cs +++ b/ThisAddIn.cs @@ -25,6 +25,7 @@ private void Application_WindowBeforeDoubleClick(Word.Selection Sel, ref bool Ca { Ribbon ribbon = Globals.Ribbons.GetRibbon(); if (!ribbon.IsEnable) return; + // Filter shapes if(Sel.Type == Word.WdSelectionType.wdSelectionShape || Sel.Type == Word.WdSelectionType.wdSelectionInlineShape) { diff --git a/WordPictureViewer.csproj b/WordPictureViewer.csproj index 0066072..bfd35d3 100644 --- a/WordPictureViewer.csproj +++ b/WordPictureViewer.csproj @@ -26,16 +26,39 @@ false WordPictureViewer WordPictureViewer - 3 v4.8 VSTO40 + False true - HomeSite + publish\ + + zh-chs + 1.0.0.0 + false + true + 7 + days + WordPictureViewer + + + WordPictureViewer + + 3 + + False + Microsoft .NET Framework 4.8 %28x86 和 x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + False - Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29 + Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 和 x64%29 true @@ -238,8 +261,8 @@ - - + + diff --git a/example_01.png b/example_01.png new file mode 100644 index 0000000..d8f9206 Binary files /dev/null and b/example_01.png differ diff --git a/example_02.png b/example_02.png new file mode 100644 index 0000000..aabb5e6 Binary files /dev/null and b/example_02.png differ