Notepad: Fix-a-possible-rounding-error-when-storing-the-font-point-size-to-the-registry
Rolf Kalbermatter
r.kalbermatter at hccnet.nl
Sun Apr 1 09:23:31 CDT 2007
Changelog
programs/notepad/main.c
On a native compilation choosing a point size of 10 resulted in getting
back 9 due to rounding errors in the calculation. By first applying the
entire multiplication and using MulDiv() to avoid theoretical integer
overflow this can be avoided.
License: X11/LGPL
Rolf Kalbermatter
-------------- next part --------------
>From d978718ac98ad9e98ffb4caa1c8bc93014c4eebf Mon Sep 17 00:00:00 2001
From: Rolf Kalbermatter <r.kalbermatter at hccnet.nl>
Date: Sat, 31 Mar 2007 23:12:31 +0200
Subject: [PATCH] Fix a possible rounding error when storing the font point size to the registry
---
programs/notepad/main.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/programs/notepad/main.c b/programs/notepad/main.c
index af00954..c6009d0 100644
--- a/programs/notepad/main.c
+++ b/programs/notepad/main.c
@@ -144,7 +144,8 @@ #define SET_NOTEPAD_REG(hkey, value_name
SET_NOTEPAD_REG(hkey, value_iMarginRight, Globals.iMarginRight);
#undef SET_NOTEPAD_REG
- data = (DWORD)(abs(Globals.lfFont.lfHeight) * 72 / get_dpi() * 10); /* method of native notepad.exe */
+ /* Store the current value as 10 * twips */
+ data = MulDiv(abs(Globals.lfFont.lfHeight), 720 , get_dpi());
RegSetValueEx(hkey, value_iPointSize, 0, REG_DWORD, (LPBYTE)&data, sizeof(DWORD));
RegSetValueEx(hkey, value_lfFaceName, 0, REG_SZ, (LPBYTE)&Globals.lfFont.lfFaceName,
@@ -239,7 +240,8 @@ #undef QUERY_NOTEPAD_REG
size = sizeof(DWORD);
if(RegQueryValueEx(hkey, value_iPointSize, 0, &type, (LPBYTE)&data, &size) == ERROR_SUCCESS)
if(type == REG_DWORD)
- Globals.lfFont.lfHeight = (LONG)(-abs(data / 10 * get_dpi() / 72)); /* method of native notepad.exe */
+ /* The value is stored as 10 * twips */
+ Globals.lfFont.lfHeight = -MulDiv(abs(data), get_dpi(), 720);
size = sizeof(Globals.lfFont.lfFaceName);
if(RegQueryValueEx(hkey, value_lfFaceName, 0, &type, (LPBYTE)&data_helper, &size) == ERROR_SUCCESS)
--
1.4.1
More information about the wine-patches
mailing list