From 66bded44f8085f49076fcbd480cbb0a84e2a996c Mon Sep 17 00:00:00 2001
From: jdishaw <jim@dishaw.org>
Date: Tue, 17 Mar 2015 13:22:49 -0400
Subject: [PATCH] - 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 |   46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/src/plmetafile.c b/src/plmetafile.c
index f26f02e..f7e2718 100644
--- a/src/plmetafile.c
+++ b/src/plmetafile.c
@@ -32,6 +32,14 @@
 
 #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 );
+
 // Status codes
 enum _plm_status
 {
@@ -481,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 );
@@ -523,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 );
@@ -570,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];
@@ -584,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];
@@ -641,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 );
@@ -699,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

