Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
theyangfan committed May 24, 2024
1 parent d24c737 commit 8da9397
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 301 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

This project is a Word VSTO add-in program (plug-in) for **double-click to enlarge** browse pictures in Office Word documents.

![Example](https://github.com/theyangfan/WordPictureViewer/blob/main/example.gif)
![Example](images/example_01.png)

![Example02](images/example_02.png)



## 下载 (Downloads)

| Office AddIn | Download |
| ------------ | ---------------------------------------------------------------------------------------------------------- |
| Word | [word_v1.0.3.zip](https://github.com/theyangfan/WordPictureViewer/releases/download/1.0.3/word_v1.0.3.zip) |
| Office AddIn | Download |
| ------------ | --------------------------------------------------------------------------------------------------------------------- |
| Word | [word_v1.1.0.zip (20240524)](https://github.com/theyangfan/WordPictureViewer/releases/download/1.1.0/word_v1.1.0.zip) |

## 安装 (Install)

Expand All @@ -26,6 +30,11 @@ Open Windows Settings, go to 【Apps】 - 【Apps and Features】, search for Wo

## 更新日志 (Release History)

### v1.1.0 (2024-05-24)

- 更新浏览界面;
- 新增图片保存和使用本机默认照片程序打开功能。

### v1.0.3 (2023-09-04)

- 最小缩放率调整为 50%。
Expand Down
Binary file removed images/example.gif
Binary file not shown.
Binary file added images/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 images/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.
101 changes: 61 additions & 40 deletions src/PictureViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,16 @@ namespace WordPictureViewer
public partial class PictureViewer : Window
{
#region Private Members
private const int MINIMUM_SCALE = 50;
private const int MINIMUM_SCALE = 50; // 50%
private Bitmap _bitmap = null;
private double _screenW;
private double _screenH;
private double _oriWidth;
private double _oriHeight;
private int _scale = 100;
private int _scale = 100; // 100%
private int _scaleStep = 10;
private bool _zoomIn = true;
private bool _isZoomIn = true;

private bool _isPressed = false;
private System.Windows.Point _pressedPoint;
private bool _isPressed = false;
private double _lastXOffset = 0;
private double _lastYOffset = 0;
#endregion
Expand All @@ -58,7 +56,7 @@ public PictureViewer()

InitUI();

// Mouse wheel event
// Mouse events
MouseWheel += PictureViewer_MouseWheel;

uiContent.MouseDown += PictureViewer_MouseDown;
Expand Down Expand Up @@ -95,16 +93,16 @@ public void ShowInlineShapeSelection(Word.Selection sel)
_bitmap = Crop(srcBmp, 0, 0, (int)_oriWidth, (int)_oriHeight);
lblPicSize.Content = $"{_bitmap.Width} x {_bitmap.Height}";
double ratio = (double)_oriWidth / _oriHeight;
_screenW = SystemParameters.PrimaryScreenWidth;
_screenH = SystemParameters.PrimaryScreenHeight;
if (_oriWidth > _screenW)
double screenW = SystemParameters.PrimaryScreenWidth;
double screenH = SystemParameters.PrimaryScreenHeight;
if (_oriWidth > screenW)
{
_oriWidth = _screenW;
_oriWidth = screenW;
_oriHeight = _oriWidth / ratio;
}
if (_oriHeight > _screenH)
if (_oriHeight > screenH)
{
_oriHeight = _screenH;
_oriHeight = screenH;
_oriWidth = _oriHeight * ratio;
}
_oriWidth *= 0.8;
Expand Down Expand Up @@ -192,20 +190,23 @@ public void ShowFloatingShapeSelection(Word.Selection sel)
#region Private Methods
private void InitUI()
{
uiLogo.ToolTip = ResourceHelper.Current.GetString("AppName");
uiBtnSave.ToolTip = ResourceHelper.Current.GetString("SaveAs");
uiBtnOpenWith.ToolTip = ResourceHelper.Current.GetString("OpenWith");
uiBtnZoomIn.ToolTip = ResourceHelper.Current.GetString("ZoomIn");
uiBtnZoomOut.ToolTip = ResourceHelper.Current.GetString("ZoomOut");
uiBtnCentered.ToolTip = ResourceHelper.Current.GetString("AlignCenter");
// set button tooltip
uiLogo.ToolTip = ResourceHelper.Strings.GetString("AppName");
uiBtnSave.ToolTip = ResourceHelper.Strings.GetString("SaveAs");
uiBtnOpenWith.ToolTip = ResourceHelper.Strings.GetString("OpenWith");
uiBtnZoomIn.ToolTip = ResourceHelper.Strings.GetString("ZoomIn");
uiBtnZoomOut.ToolTip = ResourceHelper.Strings.GetString("ZoomOut");
uiBtnCentered.ToolTip = ResourceHelper.Strings.GetString("AlignCenter");
}

private void ZoomIn()
{
double scale = (double)_scale / 100;
if (_zoomIn && _scale > 100) _scaleStep++;
// scale step increase when zoom in
if (_isZoomIn && _scale > 100) _scaleStep++;

_scale += _scaleStep;
_zoomIn = true;
_isZoomIn = true;
double newScale = (double)_scale / 100;

Scale(scale, newScale, _oriWidth / 2, _oriHeight / 2);
Expand All @@ -219,10 +220,12 @@ private void ZoomIn()
private void ZoomOut()
{
double scale = (double)_scale / 100;
if (!_zoomIn && _scale > 100) _scaleStep--;
// scale step decrease when zoom out
if (!_isZoomIn && _scale > 100) _scaleStep--;

if (_scale - _scaleStep < MINIMUM_SCALE) return;
_scale -= _scaleStep;
_zoomIn = false;
_isZoomIn = false;
double newScale = (double)_scale / 100;

Scale(scale, newScale, _oriWidth / 2, _oriHeight / 2);
Expand Down Expand Up @@ -350,33 +353,49 @@ private void PictureViewer_MouseMove(object sender, MouseEventArgs e)
uiTranslate.X = _lastXOffset + offset.X;
uiTranslate.Y = _lastYOffset + offset.Y;
}

private void btnSave_Click(object sender, RoutedEventArgs e)
{
if(_bitmap == null)
try
{
if (_bitmap == null)
{
MessageBox.Show("Invalid Picture!");
return;
}
Microsoft.Win32.SaveFileDialog save = new Microsoft.Win32.SaveFileDialog();
save.Filter = "Jpeg Files (*.jpg, *.jpeg)|*.jpg;*.jpeg | Png files (*.png) |*.png | Bmp Files (*.bmp)|*.bmp " +
"| Gif Files (*.gif)|*.gif | Emf Files (*.emf)|*.emf | All Files (*.*)|*.*";
if (save.ShowDialog() != true) return;
string ext = new FileInfo(save.FileName).Extension;
ImageFormat format = GetImageFormat(ext);

_bitmap.Save(save.FileName, format);
}
catch (Exception ex)
{
MessageBox.Show("Invalid Picture!");
return;
MessageBox.Show(ex.Message);
}
Microsoft.Win32.SaveFileDialog save = new Microsoft.Win32.SaveFileDialog();
save.Filter = "Jpeg Files (*.jpg, *.jpeg)|*.jpg;*.jpeg | Png files (*.png) |*.png | Bmp Files (*.bmp)|*.bmp " +
"| Gif Files (*.gif)|*.gif | Emf Files (*.emf)|*.emf | All Files (*.*)|*.*";
if (save.ShowDialog() != true) return;
string ext = new FileInfo(save.FileName).Extension;
ImageFormat format = GetImageFormat(ext);

_bitmap.Save(save.FileName, format);
}

private void btnOpenWith_Click(object sender, RoutedEventArgs e)
{
if (_bitmap == null)
try
{
if (_bitmap == null)
{
MessageBox.Show("Invalid Picture!");
return;
}
string tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"WordPictureViewer-{Guid.NewGuid()}.jpg");
_bitmap.Save(tempFile, ImageFormat.Jpeg);
System.Diagnostics.Process.Start(tempFile);
}
catch (Exception ex)
{
MessageBox.Show("Invalid Picture!");
return;
MessageBox.Show(ex.Message);
}
string tempFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"WordPictureViewer-{Guid.NewGuid()}.jpg");
_bitmap.Save(tempFile, ImageFormat.Jpeg);
System.Diagnostics.Process.Start(tempFile);

}

private void btnClose_Click(object sender, RoutedEventArgs e)
Expand All @@ -397,6 +416,7 @@ private void btnZoomIn_Click(object sender, RoutedEventArgs e)

private void btnCentered_Click(object sender, RoutedEventArgs e)
{
// reset translate offset
uiTranslate.X = 0;
uiTranslate.Y = 0;
_lastXOffset = 0;
Expand All @@ -407,6 +427,7 @@ private void Window_KeyDown(object sender, KeyEventArgs e)
{
if(e.Key == Key.Escape)
{
if (_bitmap != null) _bitmap.Dispose();
Close();
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Reflection;
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
Expand All @@ -11,7 +12,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WordPictureViewer")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -33,6 +34,5 @@
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”: :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
62 changes: 0 additions & 62 deletions src/Properties/Resources.Designer.cs

This file was deleted.

Loading

0 comments on commit 8da9397

Please sign in to comment.