Huw Davies : wineps.drv:
Add a heuristic to cope with resolution strings of the form "nnnmmmdpi"
( ie without the 'x' separator).
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Apr 10 14:58:06 CDT 2007
Module: wine
Branch: master
Commit: f7f5ed19965ecb32cab793deba3f075c671f9c86
URL: http://source.winehq.org/git/wine.git/?a=commit;h=f7f5ed19965ecb32cab793deba3f075c671f9c86
Author: Huw Davies <huw at codeweavers.com>
Date: Tue Apr 10 14:09:44 2007 +0100
wineps.drv: Add a heuristic to cope with resolution strings of the form "nnnmmmdpi" (ie without the 'x' separator).
---
dlls/wineps.drv/ppd.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/dlls/wineps.drv/ppd.c b/dlls/wineps.drv/ppd.c
index 130613a..d52f6f9 100644
--- a/dlls/wineps.drv/ppd.c
+++ b/dlls/wineps.drv/ppd.c
@@ -516,6 +516,70 @@ static char *PSDRV_PPDGetWord(char *str, char **next)
return ret;
}
+/************************************************************
+ * parse_resolution
+ *
+ * Helper to extract x and y resolutions from a resolution entry.
+ * Returns TRUE on successful parsing, otherwise FALSE.
+ *
+ * The ppd spec says that entries can either be:
+ * "nnndpi"
+ * or
+ * "nnnxmmmdpi"
+ * in the former case return sz.cx == cx.cy == nnn.
+ *
+ * There are broken ppd files out there (notably from Samsung) that
+ * use the form "nnnmmmdpi", so we have to work harder to spot these.
+ * We use a transition from a zero to a non-zero digit as separator
+ * (and fail if we find more than one of these). We also don't bother
+ * trying to parse "dpi" in case that's missing.
+ */
+static BOOL parse_resolution(const char *str, SIZE *sz)
+{
+ int tmp[2];
+ int *cur;
+ BOOL had_zero;
+ const char *c;
+
+ if(sscanf(str, "%dx%d", tmp, tmp + 1) == 2)
+ {
+ sz->cx = tmp[0];
+ sz->cy = tmp[1];
+ return TRUE;
+ }
+
+ tmp[0] = 0;
+ tmp[1] = -1;
+ cur = tmp;
+ had_zero = FALSE;
+ for(c = str; isdigit(*c); c++)
+ {
+ if(!had_zero || *c == '0')
+ {
+ *cur *= 10;
+ *cur += *c - '0';
+ if(*c == '0')
+ had_zero = TRUE;
+ }
+ else if(cur != tmp)
+ return FALSE;
+ else
+ {
+ cur++;
+ *cur = *c - '0';
+ had_zero = FALSE;
+ }
+ }
+ if(tmp[0] == 0) return FALSE;
+
+ sz->cx = tmp[0];
+ if(tmp[1] != -1)
+ sz->cy = tmp[1];
+ else
+ sz->cy = sz->cx;
+ return TRUE;
+}
+
/*******************************************************************************
* PSDRV_AddSlot
*
@@ -605,8 +669,14 @@ PPD *PSDRV_ParsePPD(char *fname)
else if((!strcmp("*DefaultResolution", tuple.key)) ||
(!strcmp("*DefaultJCLResolution", tuple.key))) {
- sscanf(tuple.value, "%d", &(ppd->DefaultResolution));
- TRACE("DefaultResolution = %d\n", ppd->DefaultResolution);
+ SIZE sz;
+ if(parse_resolution(tuple.value, &sz))
+ {
+ TRACE("DefaultResolution %dx%d\n", sz.cx, sz.cy);
+ ppd->DefaultResolution = sz.cx;
+ }
+ else
+ WARN("failed to parse DefaultResolution %s\n", debugstr_a(tuple.value));
}
else if(!strcmp("*Font", tuple.key)) {
More information about the wine-cvs
mailing list