[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: pcb.git: branch: master updated (5e84cc5f5506958cec38b440a43b23c4227658ad)
The branch, master has been updated
via 5e84cc5f5506958cec38b440a43b23c4227658ad (commit)
via ca98e2da2b9d0d9fc20afa418d3e2a5f2084418c (commit)
from 1757783e412e38da9a802b904477540466058468 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
=========
Summary
=========
configure.ac | 44 ++++++++++++++++++++++++++++++++++++++++++++
globalconst.h | 10 +++++++++-
src/const.h | 5 +++++
src/draw.c | 18 +++++++++---------
src/global.h | 9 ++++++++-
src/misc.c | 10 +++++-----
src/print.c | 6 +++---
src/report.c | 4 ++--
8 files changed, 85 insertions(+), 21 deletions(-)
=================
Commit Messages
=================
commit 5e84cc5f5506958cec38b440a43b23c4227658ad
Author: DJ Delorie <dj@xxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>
Fix text scaling exceeding Coord max.
The old way of scaling text was to multiply by scale/100 but this could
easily overflow on reasonably sized boards with a 32-bit Coord type.
The new code scales by (double)scale/100.0 instead. Since we don't
store scaled values in the PCB file, a loss of precision won't matter,
but a double has 53 bits of precision - in nanometers, that's a board
about the size of North America.
Closes-bug: lp-832451
:100644 100644 0885871... f029821... M src/const.h
:100644 100644 f8db2ba... deb9e65... M src/draw.c
:100644 100644 1000400... a2a678e... M src/misc.c
:100644 100644 7e7e412... 4c01721... M src/print.c
:100644 100644 f640ef0... 4d5e27b... M src/report.c
commit ca98e2da2b9d0d9fc20afa418d3e2a5f2084418c
Author: DJ Delorie <dj@xxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>
Add configure selection of 32/64 Coord type
--enable-coord64 Force 64-bit coordinate types
--enable-coord32 Force 32-bit coordinate types
Defaults to "long" as before, but if you give one of the above,
the type changes to a suitable 32-bit or 64-bit type. Note
that this is only guaranteed to be the size you choose if you
have <stdint.h> which most OSs provide, else the "int" and "long long"
types are used instead.
:100644 100644 20b5cd3... 71ab1c4... M configure.ac
:100755 100755 e85b360... e8966ff... M globalconst.h
:100644 100644 a3a4ac1... 96c9cc9... M src/global.h
=========
Changes
=========
commit 5e84cc5f5506958cec38b440a43b23c4227658ad
Author: DJ Delorie <dj@xxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>
Fix text scaling exceeding Coord max.
The old way of scaling text was to multiply by scale/100 but this could
easily overflow on reasonably sized boards with a 32-bit Coord type.
The new code scales by (double)scale/100.0 instead. Since we don't
store scaled values in the PCB file, a loss of precision won't matter,
but a double has 53 bits of precision - in nanometers, that's a board
about the size of North America.
Closes-bug: lp-832451
diff --git a/src/const.h b/src/const.h
index 0885871..f029821 100644
--- a/src/const.h
+++ b/src/const.h
@@ -75,6 +75,11 @@
#define COORD_TO_INCH(n) (COORD_TO_MIL(n) / 1000.0)
#define INCH_TO_COORD(n) (MIL_TO_COORD(n) * 1000.0)
+/* These need to be carefully written to avoid overflows, and return
+ a Coord type. */
+#define SCALE_TEXT(COORD,TEXTSCALE) ((Coord)((COORD) * ((double)(TEXTSCALE) / 100.0)))
+#define UNSCALE_TEXT(COORD,TEXTSCALE) ((Coord)((COORD) * (100.0 / (double)(TEXTSCALE))))
+
/* ---------------------------------------------------------------------------
* modes
*/
diff --git a/src/draw.c b/src/draw.c
index f8db2ba..deb9e65 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -1222,11 +1222,11 @@ DrawTextLowLevel (TextTypePtr Text, Coord min_line_width)
{
/* create one line, scale, move, rotate and swap it */
newline = *line;
- newline.Point1.X = (newline.Point1.X + x) * Text->Scale / 100;
- newline.Point1.Y = newline.Point1.Y * Text->Scale / 100;
- newline.Point2.X = (newline.Point2.X + x) * Text->Scale / 100;
- newline.Point2.Y = newline.Point2.Y * Text->Scale / 100;
- newline.Thickness = newline.Thickness * Text->Scale / 200;
+ newline.Point1.X = SCALE_TEXT (newline.Point1.X + x, Text->Scale);
+ newline.Point1.Y = SCALE_TEXT (newline.Point1.Y, Text->Scale);
+ newline.Point2.X = SCALE_TEXT (newline.Point2.X + x, Text->Scale);
+ newline.Point2.Y = SCALE_TEXT (newline.Point2.Y, Text->Scale);
+ newline.Thickness = SCALE_TEXT (newline.Thickness, Text->Scale / 2);
if (newline.Thickness < min_line_width)
newline.Thickness = min_line_width;
@@ -1259,10 +1259,10 @@ DrawTextLowLevel (TextTypePtr Text, Coord min_line_width)
BoxType defaultsymbol = PCB->Font.DefaultSymbol;
Coord size = (defaultsymbol.X2 - defaultsymbol.X1) * 6 / 5;
- defaultsymbol.X1 = (defaultsymbol.X1 + x) * Text->Scale / 100;
- defaultsymbol.Y1 = defaultsymbol.Y1 * Text->Scale / 100;
- defaultsymbol.X2 = (defaultsymbol.X2 + x) * Text->Scale / 100;
- defaultsymbol.Y2 = defaultsymbol.Y2 * Text->Scale / 100;
+ defaultsymbol.X1 = SCALE_TEXT (defaultsymbol.X1 + x, Text->Scale);
+ defaultsymbol.Y1 = SCALE_TEXT (defaultsymbol.Y1, Text->Scale);
+ defaultsymbol.X2 = SCALE_TEXT (defaultsymbol.X2 + x, Text->Scale);
+ defaultsymbol.Y2 = SCALE_TEXT (defaultsymbol.Y2, Text->Scale);
RotateBoxLowLevel (&defaultsymbol, 0, 0, Text->Direction);
diff --git a/src/misc.c b/src/misc.c
index 1000400..a2a678e 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -516,7 +516,7 @@ SetTextBoundingBox (FontTypePtr FontPtr, TextTypePtr Text)
* bounds of the un-scaled text, and the thickness clamping applies to
* scaled text.
*/
- min_unscaled_radius = min_final_radius * 100 / Text->Scale;
+ min_unscaled_radius = UNSCALE_TEXT (min_final_radius, Text->Scale);
/* calculate size of the bounding box */
for (; s && *s; s++)
@@ -572,10 +572,10 @@ SetTextBoundingBox (FontTypePtr FontPtr, TextTypePtr Text)
}
/* scale values */
- minx = minx * Text->Scale / 100;
- miny = miny * Text->Scale / 100;
- maxx = maxx * Text->Scale / 100;
- maxy = maxy * Text->Scale / 100;
+ minx = SCALE_TEXT (minx, Text->Scale);
+ miny = SCALE_TEXT (miny, Text->Scale);
+ maxx = SCALE_TEXT (maxx, Text->Scale);
+ maxy = SCALE_TEXT (maxy, Text->Scale);
/* set upper-left and lower-right corner;
* swap coordinates if necessary (origin is already in 'swapped')
diff --git a/src/print.c b/src/print.c
index 7e7e412..4c01721 100644
--- a/src/print.c
+++ b/src/print.c
@@ -111,16 +111,16 @@ text_at (hidGC gc, int x, int y, int align, char *fmt, ...)
for (i = 0; tmp[i]; i++)
w +=
(font->Symbol[(int) tmp[i]].Width + font->Symbol[(int) tmp[i]].Delta);
- w = w * t.Scale / 100;
+ w = SCALE_TEXT (w, t.Scale);
t.X -= w * (align & 3) / 2;
if (t.X < 0)
t.X = 0;
DrawTextLowLevel (&t, 0);
if (align & 8)
fab_line (gc, t.X,
- t.Y + font->MaxHeight * t.Scale / 100 + MIL_TO_COORD(10),
+ t.Y + SCALE_TEXT (font->MaxHeight, t.Scale) + MIL_TO_COORD(10),
t.X + w,
- t.Y + font->MaxHeight * t.Scale / 100 + MIL_TO_COORD(10));
+ t.Y + SCALE_TEXT (font->MaxHeight, t.Scale) + MIL_TO_COORD(10));
}
/* Y, +, X, circle, square */
diff --git a/src/report.c b/src/report.c
index f640ef0..4d5e27b 100644
--- a/src/report.c
+++ b/src/report.c
@@ -423,7 +423,7 @@ ReportDialog (int argc, char **argv, Coord x, Coord y)
EMPTY (element->Name[0].TextString),
EMPTY (element->Name[1].TextString),
EMPTY (element->Name[2].TextString),
- (Coord) (FONT_CAPHEIGHT * element->Name[1].Scale / 100.),
+ SCALE_TEXT (FONT_CAPHEIGHT, element->Name[1].Scale),
element->Name[1].X, element->Name[1].Y,
TEST_FLAG (HIDENAMEFLAG, element) ? ",\n but it's hidden" : "",
element->MarkX, element->MarkY,
@@ -464,7 +464,7 @@ ReportDialog (int argc, char **argv, Coord x, Coord y)
"The bounding box is %$mD %$mD.\n"
"%s\n"
"%s", USER_UNITMASK, text->ID, flags_to_string (text->Flags, TEXT_TYPE),
- text->X, text->Y, (Coord) (FONT_CAPHEIGHT * (float)text->Scale / 100.),
+ text->X, text->Y, SCALE_TEXT (FONT_CAPHEIGHT, text->Scale),
text->TextString, text->Direction,
text->BoundingBox.X1, text->BoundingBox.Y1,
text->BoundingBox.X2, text->BoundingBox.Y2,
commit ca98e2da2b9d0d9fc20afa418d3e2a5f2084418c
Author: DJ Delorie <dj@xxxxxxxxxxx>
Commit: DJ Delorie <dj@xxxxxxxxxxx>
Add configure selection of 32/64 Coord type
--enable-coord64 Force 64-bit coordinate types
--enable-coord32 Force 32-bit coordinate types
Defaults to "long" as before, but if you give one of the above,
the type changes to a suitable 32-bit or 64-bit type. Note
that this is only guaranteed to be the size you choose if you
have <stdint.h> which most OSs provide, else the "int" and "long long"
types are used instead.
diff --git a/configure.ac b/configure.ac
index 20b5cd3..71ab1c4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1076,6 +1076,49 @@ AM_CONDITIONAL(DEBUG_BUILD, test x$enable_debug = xyes)
m4_include([m4/m4_ax_func_mkdir.m4])
AX_FUNC_MKDIR
+# ------------- Type used for "Coord" type -------------------
+
+AC_CHECK_HEADERS(stdint.h)
+AC_ARG_ENABLE([coord64],
+[ --enable-coord64 Force 64-bit coordinate types],
+[],[enable_coord64=no])
+AC_ARG_ENABLE([coord32],
+[ --enable-coord32 Force 32-bit coordinate types],
+[],[enable_coord32=no])
+
+COORDTYPE="long"
+
+echo "$enable_coord32:$enable_coord64:$ac_cv_header_stdint_h"
+case "$enable_coord32:$enable_coord64:$ac_cv_header_stdint_h" in
+ yes:no:yes )
+ COORD_TYPE="int32_t"
+ COORD_MAX="INT32_MAX"
+ ;;
+ no:yes:yes )
+ COORD_TYPE="int64_t"
+ COORD_MAX="INT64_MAX"
+ ;;
+ yes:no:no )
+ COORD_TYPE="int"
+ COORD_MAX="INT_MAX"
+ ;;
+ no:yes:no )
+ COORD_TYPE="long long"
+ COORD_MAX="LLONG_MAX"
+ ;;
+ yes:yes:* )
+ AC_MSG_ERROR("*** cannot require both 32 and 64 bit coordinates")
+ ;;
+ *:*:* )
+ COORD_TYPE="long"
+ COORD_MAX="LONG_MAX"
+ ;;
+esac
+AC_DEFINE_UNQUOTED([COORD_TYPE],[$COORD_TYPE],
+ [C type for Coordinates])
+AC_DEFINE_UNQUOTED([COORD_MAX],[$COORD_MAX],
+ [Maximum value of coordinate type])
+
# ------------- Complete set of CFLAGS and LIBS -------------------
CFLAGS="$CFLAGS $X_CFLAGS $DBUS_CFLAGS $GLIB_CFLAGS $GTK_CFLAGS $CAIRO_CFLAGS $GTKGLEXT_CFLAGS $GLU_CFLAGS"
@@ -1306,6 +1349,7 @@ AC_MSG_RESULT([
GUI: $with_gui
Printer: $with_printer
Exporters: $with_exporters
+ Coordinate type: $COORD_TYPE
Source tree distribution: $pcb_sources
Build documentation: $docs_yesno
Build toporouter: $enable_toporouter
diff --git a/globalconst.h b/globalconst.h
index e85b360..e8966ff 100755
--- a/globalconst.h
+++ b/globalconst.h
@@ -33,8 +33,16 @@
#ifndef __GLOBALCONST_INCLUDED__
#define __GLOBALCONST_INCLUDED__
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <limits.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
/* ---------------------------------------------------------------------------
* some file-, directory- and environment names
*/
@@ -60,7 +68,7 @@
/* ---------------------------------------------------------------------------
* some limit specifications
*/
-#define LARGE_VALUE (LONG_MAX / 2 - 1) /* maximum extent of board and elements */
+#define LARGE_VALUE (COORD_MAX / 2 - 1) /* maximum extent of board and elements */
#define MAX_LAYER 16 /* max number of layer, check source */
/* code for more changes, a *lot* more changes */
diff --git a/src/global.h b/src/global.h
index a3a4ac1..96c9cc9 100644
--- a/src/global.h
+++ b/src/global.h
@@ -38,9 +38,16 @@
#ifndef PCB_GLOBAL_H
#define PCB_GLOBAL_H
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include "const.h"
#include "macro.h"
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -64,7 +71,7 @@ typedef struct AttributeListType AttributeListType, *AttributeListTypePtr;
typedef struct unit Unit;
typedef struct increments Increments;
-typedef long Coord; /* pcb base unit */
+typedef COORD_TYPE Coord; /* pcb base unit */
typedef double Angle; /* degrees */
#include "hid.h"
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs