Newer
Older
Import / applications / MakePDF / 3rdParty / libharu / pr-patches / 0001-Patch-for-vertical-alignment-options-in-text-rectang.patch
From 256dfd3cb6f10d53df9cd76471c69e8e31ea0d28 Mon Sep 17 00:00:00 2001
From: davyjones <davyjones@github>
Date: Fri, 22 Jun 2012 16:18:22 +0900
Subject: [PATCH] Patch for vertical alignment options in text rectangles.

---
 include/hpdf.h           |  2 +-
 include/hpdf_types.h     | 11 ++++---
 src/hpdf_page_operator.c | 68 +++++++++++++++++++++++++++++++++++++++-
 3 files changed, 75 insertions(+), 6 deletions(-)

diff --git a/include/hpdf.h b/include/hpdf.h
index 7249df4..a9c0b3c 100644
--- a/include/hpdf.h
+++ b/include/hpdf.h
@@ -1520,7 +1520,7 @@ HPDF_Page_TextRect  (HPDF_Page            page,
                      HPDF_REAL            right,
                      HPDF_REAL            bottom,
                      const char          *text,
-                     HPDF_TextAlignment   align,
+                     HPDF_UINT            align,
                      HPDF_UINT           *len);
 
 
diff --git a/include/hpdf_types.h b/include/hpdf_types.h
index 8b3e0a8..656d0d3 100644
--- a/include/hpdf_types.h
+++ b/include/hpdf_types.h
@@ -543,10 +543,13 @@ typedef enum _HPDF_ByteType {
 
 
 typedef enum _HPDF_TextAlignment {
-    HPDF_TALIGN_LEFT = 0,
-    HPDF_TALIGN_RIGHT,
-    HPDF_TALIGN_CENTER,
-    HPDF_TALIGN_JUSTIFY
+    HPDF_TALIGN_LEFT = 0x00,
+    HPDF_TALIGN_RIGHT = 0x02,
+    HPDF_TALIGN_CENTER = 0x04,
+    HPDF_TALIGN_JUSTIFY = 0x08,
+    HPDF_TALIGN_TOP = 0x10,
+    HPDF_TALIGN_BOTTOM = 0x20,
+    HPDF_TALIGN_MIDDLE = 0x40,
 } HPDF_TextAlignment;
 
 /*----------------------------------------------------------------------------*/
diff --git a/src/hpdf_page_operator.c b/src/hpdf_page_operator.c
index a62db2f..e40d927 100644
--- a/src/hpdf_page_operator.c
+++ b/src/hpdf_page_operator.c
@@ -2407,7 +2407,7 @@ HPDF_Page_TextRect  (HPDF_Page            page,
                      HPDF_REAL            right,
                      HPDF_REAL            bottom,
                      const char          *text,
-                     HPDF_TextAlignment   align,
+                     HPDF_UINT            align,
                      HPDF_UINT           *len
                      )
 {
@@ -2546,6 +2546,72 @@ HPDF_Page_TextRect  (HPDF_Page            page,
                 }
                 break;
 
+            case HPDF_TALIGN_BOTTOM:
+                TextPos_AbsToRel (attr->text_matrix, left, bottom + attr->gstate->font_size, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
+            case HPDF_TALIGN_MIDDLE:
+                TextPos_AbsToRel (attr->text_matrix, left, bottom + (top - bottom + attr->gstate->font_size) / 2, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
+            case HPDF_TALIGN_CENTER | HPDF_TALIGN_BOTTOM:
+                TextPos_AbsToRel (attr->text_matrix, left + (right - left - rw) / 2, bottom + attr->gstate->font_size, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
+            case HPDF_TALIGN_CENTER | HPDF_TALIGN_MIDDLE:
+                TextPos_AbsToRel (attr->text_matrix, left + (right - left - rw) / 2, bottom + (top - bottom + attr->gstate->font_size) / 2, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
+            case HPDF_TALIGN_RIGHT | HPDF_TALIGN_BOTTOM:
+                TextPos_AbsToRel (attr->text_matrix, right - rw, bottom + attr->gstate->font_size, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
+            case HPDF_TALIGN_RIGHT | HPDF_TALIGN_MIDDLE:
+                TextPos_AbsToRel (attr->text_matrix, right - rw, bottom + (top - bottom + attr->gstate->font_size) / 2, &x, &y);
+                if (!pos_initialized) {
+                    pos_initialized = HPDF_TRUE;
+                } else {
+                    y = 0;
+                }
+                if ((ret = HPDF_Page_MoveTextPos (page, x, y)) != HPDF_OK)
+                    return ret;
+                break;
+
             default:
                 if (!pos_initialized) {
                     pos_initialized = HPDF_TRUE;
-- 
2.21.1 (Apple Git-122.3)