From 10e6e41d7cc2b4dcc0f97cb6ebb2b7dc83844c51 Mon Sep 17 00:00:00 2001
From: jdishaw <jim@dishaw.org>
Date: Tue, 17 Mar 2015 11:08:11 -0400
Subject: [PATCH] Fixed linking error in VS 2012 due missing lround(), which
 used in plmetafile.c

- VS 2012 does not implement the C99 lround() function
- The ceil() function appears to be in VS 2012
- Changed the lround() to a ceil(), which will be off by 1 for negatve numbers
compared to lround().  Due to the experimental nature of plmetafile.c, this
is not an issue.
- Wrapped ceil() inside a macro as a placeholder until a post-release fix.
---
 src/plmetafile.c |   43 ++++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/src/plmetafile.c b/src/plmetafile.c
index bb7d36e..1288080 100644
--- a/src/plmetafile.c
+++ b/src/plmetafile.c
@@ -32,6 +32,11 @@
 
 #define MAX_BUFFER    256 // Character buffer size for reading records
 
+// Not all platforms support the lround() function and the coordinate system
+// representation is going to be redone, thus this is just a placeholder until 
+// everything is sorted out.
+#define PLFLT2COORD(a)   ((short) ceil(a))
+
 // Reach into plsym.c so that symbols can be rendered correctly
 void plhrsh( PLINT ch, PLINT x, PLINT y );
 
@@ -484,10 +489,10 @@ enum _plm_status read_line( PDFstrm *plm, PLmDev *dev, PLStream *pls )
 
     // Transform the coordinates from the meta device to the current
     // device coordinate system
-    x[0] = (short) lround( dev->mfpcxa * x1 + dev->mfpcxb );
-    y[0] = (short) lround( dev->mfpcya * y1 + dev->mfpcyb );
-    x[1] = (short) lround( dev->mfpcxa * x2 + dev->mfpcxb );
-    y[1] = (short) lround( dev->mfpcya * y2 + dev->mfpcyb );
+    x[0] = PLFLT2COORD( dev->mfpcxa * x1 + dev->mfpcxb );
+    y[0] = PLFLT2COORD( dev->mfpcya * y1 + dev->mfpcyb );
+    x[1] = PLFLT2COORD( dev->mfpcxa * x2 + dev->mfpcxb );
+    y[1] = PLFLT2COORD( dev->mfpcya * y2 + dev->mfpcyb );
 
     // Draw the line
     plP_line( x, y );
@@ -526,8 +531,8 @@ enum _plm_status read_lineto( PDFstrm *plm, PLmDev *dev, PLStream *pls )
 
     // Transform the coordinates from the meta device to the current
     // device coordinate system
-    x[1] = (short) lround( dev->mfpcxa * x2 + dev->mfpcxb );
-    y[1] = (short) lround( dev->mfpcya * y2 + dev->mfpcyb );
+    x[1] = PLFLT2COORD( dev->mfpcxa * x2 + dev->mfpcxb );
+    y[1] = PLFLT2COORD( dev->mfpcya * y2 + dev->mfpcyb );
 
     // Draw the line
     plP_line( x, y );
@@ -573,7 +578,7 @@ enum _plm_status read_polyline( PDFstrm *plm, PLmDev *dev, PLStream *pls )
 
         // Transform the coordinates from the meta device to the current
         // device coordinate system
-        xd[i] = (short) lround( dev->mfpcxa * x + dev->mfpcxb );
+        xd[i] = PLFLT2COORD( dev->mfpcxa * x + dev->mfpcxb );
     }
     // Preserve the last X value for the LINETO command
     dev->xold = xd[npts - 1];
@@ -587,7 +592,7 @@ enum _plm_status read_polyline( PDFstrm *plm, PLmDev *dev, PLStream *pls )
 
         // Transform the coordinates from the meta device to the current
         // device coordinate system
-        yd[i] = (short) lround( dev->mfpcya * y + dev->mfpcyb );
+        yd[i] = PLFLT2COORD( dev->mfpcya * y + dev->mfpcyb );
     }
     // Preserve the last Y value for the LINETO command
     dev->yold = yd[npts - 1];
@@ -644,8 +649,8 @@ enum _plm_status read_escape( PDFstrm *plm, PLmDev *dev, PLStream *pls )
 
             // Transform the coordinates from the meta device to the current
             // device coordinate system
-            xd[i] = (short) lround( dev->mfpcxa * x + dev->mfpcxb );
-            yd[i] = (short) lround( dev->mfpcya * y + dev->mfpcyb );
+            xd[i] = PLFLT2COORD( dev->mfpcxa * x + dev->mfpcxb );
+            yd[i] = PLFLT2COORD( dev->mfpcya * y + dev->mfpcyb );
         }
 
         plP_fill( xd, yd, npts );
@@ -702,15 +707,15 @@ enum _plm_status read_escape( PDFstrm *plm, PLmDev *dev, PLStream *pls )
         rc = read_entry( plm, PDF_ULONG, PLP_ULONG, &text.text_type );
 
         // Translate coordinates to the device coordinate system
-        pls->clpxmi = (short) lround( dev->mfpcxa * xmin + dev->mfpcxb );
-        pls->clpxma = (short) lround( dev->mfpcxa * xmax + dev->mfpcxb );
-        pls->clpymi = (short) lround( dev->mfpcxa * ymin + dev->mfpcxb );
-        pls->clpyma = (short) lround( dev->mfpcxa * ymax + dev->mfpcxb );
-
-        text.x    = (short) lround( dev->mfpcxa * x + dev->mfpcxb );
-        text.y    = (short) lround( dev->mfpcya * y + dev->mfpcyb );
-        text.refx = (short) lround( dev->mfpcxa * refx + dev->mfpcxb );
-        text.refy = (short) lround( dev->mfpcya * refy + dev->mfpcyb );
+        pls->clpxmi = PLFLT2COORD( dev->mfpcxa * xmin + dev->mfpcxb );
+        pls->clpxma = PLFLT2COORD( dev->mfpcxa * xmax + dev->mfpcxb );
+        pls->clpymi = PLFLT2COORD( dev->mfpcxa * ymin + dev->mfpcxb );
+        pls->clpyma = PLFLT2COORD( dev->mfpcxa * ymax + dev->mfpcxb );
+
+        text.x    = PLFLT2COORD( dev->mfpcxa * x + dev->mfpcxb );
+        text.y    = PLFLT2COORD( dev->mfpcya * y + dev->mfpcyb );
+        text.refx = PLFLT2COORD( dev->mfpcxa * refx + dev->mfpcxb );
+        text.refy = PLFLT2COORD( dev->mfpcya * refy + dev->mfpcyb );
 
         if ( text.text_type == PL_STRING_TEXT )
         {
-- 
1.7.10.4

