Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yangfan committed Jan 17, 2023
1 parent c803b09 commit acd658d
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.vs/*
bin/*
obj/*
obj/*
publish/*
*.user
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.

21 changes: 14 additions & 7 deletions PictureViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ namespace WordPictureViewer
/// </summary>
public partial class PictureViewer : Window
{
#region Private Members
private int _scale = 100;
private int _scaleStep = 9;
#endregion

#region Constructor
public PictureViewer(Bitmap bitmap)
{
InitializeComponent();
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -107,5 +113,6 @@ private void UICloseBtn_Click(object sender, RoutedEventArgs e)
{
Close();
}
#endregion
}
}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 12 additions & 2 deletions Ribbon.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Ribbon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public bool IsEnable

private void Ribbon_Load(object sender, RibbonUIEventArgs e)
{

}
}
}
1 change: 1 addition & 0 deletions ThisAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private void Application_WindowBeforeDoubleClick(Word.Selection Sel, ref bool Ca
{
Ribbon ribbon = Globals.Ribbons.GetRibbon<Ribbon>();
if (!ribbon.IsEnable) return;
// Filter shapes
if(Sel.Type == Word.WdSelectionType.wdSelectionShape
|| Sel.Type == Word.WdSelectionType.wdSelectionInlineShape)
{
Expand Down
33 changes: 28 additions & 5 deletions WordPictureViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,39 @@
<NoStandardLibraries>false</NoStandardLibraries>
<RootNamespace>WordPictureViewer</RootNamespace>
<AssemblyName>WordPictureViewer</AssemblyName>
<LoadBehavior>3</LoadBehavior>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<DefineConstants>VSTO40</DefineConstants>
<IsWebBootstrapper>False</IsWebBootstrapper>
<BootstrapperEnabled>true</BootstrapperEnabled>
<BootstrapperComponentsLocation>HomeSite</BootstrapperComponentsLocation>
<PublishUrl>publish\</PublishUrl>
<InstallUrl />
<TargetCulture>zh-chs</TargetCulture>
<ApplicationVersion>1.0.0.0</ApplicationVersion>
<AutoIncrementApplicationRevision>false</AutoIncrementApplicationRevision>
<UpdateEnabled>true</UpdateEnabled>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>days</UpdateIntervalUnits>
<ProductName>WordPictureViewer</ProductName>
<PublisherName />
<SupportUrl />
<FriendlyName>WordPictureViewer</FriendlyName>
<OfficeApplicationDescription />
<LoadBehavior>3</LoadBehavior>
</PropertyGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 和 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.VSTORuntime.4.0">
<Visible>False</Visible>
<ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 and x64%29</ProductName>
<ProductName>Microsoft Visual Studio 2010 Tools for Office Runtime %28x86 x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
Expand Down Expand Up @@ -238,8 +261,8 @@
<VisualStudio>
<FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
<ProjectProperties HostName="Word" HostPackage="{29A7B9D7-A7F1-4328-8EF0-6B2D1A56B2C1}" OfficeVersion="15.0" VstxVersion="4.0" ApplicationType="Word" Language="cs" TemplatesPath="" DebugInfoExeName="#Software\Microsoft\Office\16.0\Word\InstallRoot\Path#WINWORD.EXE" DebugInfoCommandLine="/x" AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
<Host Name="Word" GeneratedCodeNamespace="WordPictureViewer" IconIndex="0">
<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" />
<Host Name="Word" GeneratedCodeNamespace="WordPictureViewer" PublishedHash="69C324AB27932AA2FBF2B7EA72250886FF164DE6" IconIndex="0">
<HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" PublishedHash="F60C0D6341E683D01C5F19FEE4DAF9C4924FD6E7" />
</Host>
</FlavorProperties>
</VisualStudio>
Expand Down
Binary file added example_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_02.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit acd658d

Please sign in to comment.