From a8297d2b66ebec0062dd58acba20a0dfbd56e1d8 Mon Sep 17 00:00:00 2001 From: Xylar Asay-Davis Date: Tue, 5 May 2020 20:10:28 +0200 Subject: [PATCH 1/2] Add two common patches https://github.com/libharu/libharu/pull/157 https://github.com/libharu/libharu/pull/187 --- recipe/0002-add-support-for-free-form.patch | 527 ++++++++++++++++++ ...ve-small-number-writing-in-HPDF-FToA.patch | 94 ++++ recipe/meta.yaml | 4 +- 3 files changed, 624 insertions(+), 1 deletion(-) create mode 100644 recipe/0002-add-support-for-free-form.patch create mode 100644 recipe/0003-improve-small-number-writing-in-HPDF-FToA.patch diff --git a/recipe/0002-add-support-for-free-form.patch b/recipe/0002-add-support-for-free-form.patch new file mode 100644 index 0000000..2ab51a9 --- /dev/null +++ b/recipe/0002-add-support-for-free-form.patch @@ -0,0 +1,527 @@ +From 9e8ba2f5453552909e52fde5ec30856004a616d0 Mon Sep 17 00:00:00 2001 +From: "David C. Lonie" +Date: Wed, 10 May 2017 11:07:28 -0400 +Subject: [PATCH] Add support for free-form triangle Shading objects. + +--- + include/hpdf.h | 24 +++- + include/hpdf_error.h | 3 + + include/hpdf_objects.h | 2 + + include/hpdf_pages.h | 5 + + include/hpdf_types.h | 14 +++ + src/CMakeLists.txt | 1 + + src/hpdf_page_operator.c | 31 ++++++ + src/hpdf_pages.c | 55 +++++++++- + src/hpdf_shading.c | 231 +++++++++++++++++++++++++++++++++++++++ + 9 files changed, 362 insertions(+), 4 deletions(-) + create mode 100644 src/hpdf_shading.c + +diff --git a/include/hpdf.h b/include/hpdf.h +index e369f67..40e3c41 100644 +--- a/include/hpdf.h ++++ b/include/hpdf.h +@@ -77,6 +77,7 @@ typedef HPDF_HANDLE HPDF_Dict; + typedef HPDF_HANDLE HPDF_EmbeddedFile; + typedef HPDF_HANDLE HPDF_OutputIntent; + typedef HPDF_HANDLE HPDF_Xref; ++typedef HPDF_HANDLE HPDF_Shading; + + #else + +@@ -1171,6 +1172,11 @@ HPDF_EXPORT(HPDF_STATUS) + HPDF_Page_SetExtGState (HPDF_Page page, + HPDF_ExtGState ext_gstate); + ++/* sh */ ++HPDF_EXPORT(HPDF_STATUS) ++HPDF_Page_SetShading (HPDF_Page page, ++ HPDF_Shading shading); ++ + + /*--- Special graphic state operator --------------------------------------*/ + +@@ -1450,7 +1456,23 @@ HPDF_Page_SetCMYKStroke (HPDF_Page page, + + /*--- Shading patterns ---------------------------------------------------*/ + +-/* sh --not implemented yet */ ++/* Notes for docs: ++ * - ShadingType must be HPDF_SHADING_FREE_FORM_TRIANGLE_MESH (the only ++ * defined option...) ++ * - colorSpace must be HPDF_CS_DEVICE_RGB for now. ++ */ ++HPDF_EXPORT(HPDF_Shading) ++HPDF_Shading_New (HPDF_Doc pdf, ++ HPDF_ShadingType type, ++ HPDF_ColorSpace colorSpace, ++ HPDF_REAL xMin, HPDF_REAL xMax, ++ HPDF_REAL yMin, HPDF_REAL yMax); ++ ++HPDF_EXPORT(HPDF_STATUS) ++HPDF_Shading_AddVertexRGB(HPDF_Shading shading, ++ HPDF_Shading_FreeFormTriangleMeshEdgeFlag edgeFlag, ++ HPDF_REAL x, HPDF_REAL y, ++ HPDF_UINT8 r, HPDF_UINT8 g, HPDF_UINT8 b); + + /*--- In-line images -----------------------------------------------------*/ + +diff --git a/include/hpdf_error.h b/include/hpdf_error.h +index b04e2cd..ef4fa61 100644 +--- a/include/hpdf_error.h ++++ b/include/hpdf_error.h +@@ -145,6 +145,9 @@ extern "C" { + #define HPDF_INVALID_U3D_DATA 0x1083 + #define HPDF_NAME_CANNOT_GET_NAMES 0x1084 + #define HPDF_INVALID_ICC_COMPONENT_NUM 0x1085 ++/* 0x1086 */ ++/* 0x1087 */ ++#define HPDF_INVALID_SHADING_TYPE 0x1088 + + /*---------------------------------------------------------------------------*/ + +diff --git a/include/hpdf_objects.h b/include/hpdf_objects.h +index 525adda..b16de02 100644 +--- a/include/hpdf_objects.h ++++ b/include/hpdf_objects.h +@@ -61,6 +61,7 @@ extern "C" { + #define HPDF_OSUBCLASS_EXT_GSTATE_R 0x0B00 /* read only object */ + #define HPDF_OSUBCLASS_NAMEDICT 0x0C00 + #define HPDF_OSUBCLASS_NAMETREE 0x0D00 ++#define HPDF_OSUBCLASS_SHADING 0x0E00 + + + +@@ -595,6 +596,7 @@ typedef HPDF_Array HPDF_Destination; + typedef HPDF_Dict HPDF_U3D; + typedef HPDF_Dict HPDF_OutputIntent; + typedef HPDF_Dict HPDF_JavaScript; ++typedef HPDF_Dict HPDF_Shading; + + #ifdef __cplusplus + } +diff --git a/include/hpdf_pages.h b/include/hpdf_pages.h +index 44b816c..60b1d84 100644 +--- a/include/hpdf_pages.h ++++ b/include/hpdf_pages.h +@@ -55,6 +55,7 @@ typedef struct _HPDF_PageAttr_Rec { + HPDF_Dict fonts; + HPDF_Dict xobjects; + HPDF_Dict ext_gstates; ++ HPDF_Dict shadings; + HPDF_GState gstate; + HPDF_Point str_pos; + HPDF_Point cur_pos; +@@ -101,6 +102,10 @@ const char* + HPDF_Page_GetExtGStateName (HPDF_Page page, + HPDF_ExtGState gstate); + ++const char* ++HPDF_Page_GetShadingName (HPDF_Page page, ++ HPDF_Shading shading); ++ + + HPDF_Box + HPDF_Page_GetMediaBox (HPDF_Page page); +diff --git a/include/hpdf_types.h b/include/hpdf_types.h +index 8b3e0a8..a2e2157 100644 +--- a/include/hpdf_types.h ++++ b/include/hpdf_types.h +@@ -557,6 +557,20 @@ typedef enum _HPDF_NameDictKey { + HPDF_NAME_EOF + } HPDF_NameDictKey; + ++/*----------------------------------------------------------------------------*/ ++ ++typedef enum _HPDF_ShadingType { ++ HPDF_SHADING_FREE_FORM_TRIANGLE_MESH = 4 /* TODO the rest */ ++} HPDF_ShadingType; ++ ++typedef enum _HPDF_Shading_FreeFormTriangleMeshEdgeFlag { ++ HPDF_FREE_FORM_TRI_MESH_EDGEFLAG_NO_CONNECTION = 0, ++ HPDF_FREE_FORM_TRI_MESH_EDGEFLAG_BC, ++ HPDF_FREE_FORM_TRI_MESH_EDGEFLAG_AC ++} HPDF_Shading_FreeFormTriangleMeshEdgeFlag; ++ ++/*----------------------------------------------------------------------------*/ ++ + #ifdef __cplusplus + } + #endif /* __cplusplus */ +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 9d2a604..71c7d10 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -56,6 +56,7 @@ set( + hpdf_page_operator.c + hpdf_pages.c + hpdf_real.c ++ hpdf_shading.c + hpdf_streams.c + hpdf_string.c + hpdf_u3d.c +diff --git a/src/hpdf_page_operator.c b/src/hpdf_page_operator.c +index 23f5920..dda1078 100644 +--- a/src/hpdf_page_operator.c ++++ b/src/hpdf_page_operator.c +@@ -312,6 +312,37 @@ HPDF_Page_SetExtGState (HPDF_Page page, + return ret; + } + ++/* sh */ ++HPDF_EXPORT(HPDF_STATUS) ++HPDF_Page_SetShading (HPDF_Page page, ++ HPDF_Shading shading) ++{ ++ HPDF_STATUS ret = HPDF_Page_CheckState (page, HPDF_GMODE_PAGE_DESCRIPTION); ++ HPDF_PageAttr attr; ++ const char *local_name; ++ ++ HPDF_PTRACE ((" HPDF_Page_SetShading\n")); ++ ++ if (ret != HPDF_OK) ++ return ret; ++ ++ if (page->mmgr != shading->mmgr) ++ return HPDF_RaiseError (page->error, HPDF_INVALID_OBJECT, 0); ++ ++ attr = (HPDF_PageAttr)page->attr; ++ local_name = HPDF_Page_GetShadingName (page, shading); ++ ++ if (!local_name) ++ return HPDF_CheckError (page->error); ++ ++ if (HPDF_Stream_WriteEscapeName (attr->stream, local_name) != HPDF_OK) ++ return HPDF_CheckError (page->error); ++ ++ if (HPDF_Stream_WriteStr (attr->stream, " sh\012") != HPDF_OK) ++ return HPDF_CheckError (page->error); ++ ++ return ret; ++} + + /*--- Special graphic state operator --------------------------------------*/ + +diff --git a/src/hpdf_pages.c b/src/hpdf_pages.c +index fcc9b5c..c0a7c4f 100644 +--- a/src/hpdf_pages.c ++++ b/src/hpdf_pages.c +@@ -514,7 +514,7 @@ HPDF_Page_GetLocalFontName (HPDF_Page page, + /* search font-object from font-resource */ + key = HPDF_Dict_GetKeyByObj (attr->fonts, font); + if (!key) { +- /* if the font is not resisterd in font-resource, register font to ++ /* if the font is not registered in font-resource, register font to + * font-resource. + */ + char fontName[HPDF_LIMIT_MAX_NAME_LEN + 1]; +@@ -603,7 +603,7 @@ HPDF_Page_GetXObjectName (HPDF_Page page, + /* search xobject-object from xobject-resource */ + key = HPDF_Dict_GetKeyByObj (attr->xobjects, xobj); + if (!key) { +- /* if the xobject is not resisterd in xobject-resource, register ++ /* if the xobject is not registered in xobject-resource, register + * xobject to xobject-resource. + */ + char xobj_name[HPDF_LIMIT_MAX_NAME_LEN + 1]; +@@ -654,7 +654,7 @@ HPDF_Page_GetExtGStateName (HPDF_Page page, + /* search ext_gstate-object from ext_gstate-resource */ + key = HPDF_Dict_GetKeyByObj (attr->ext_gstates, state); + if (!key) { +- /* if the ext-gstate is not resisterd in ext-gstate resource, register ++ /* if the ext-gstate is not registered in ext-gstate resource, register + * to ext-gstate resource. + */ + char ext_gstate_name[HPDF_LIMIT_MAX_NAME_LEN + 1]; +@@ -673,6 +673,55 @@ HPDF_Page_GetExtGStateName (HPDF_Page page, + return key; + } + ++const char* ++HPDF_Page_GetShadingName (HPDF_Page page, ++ HPDF_Shading shading) ++{ ++ HPDF_PageAttr attr = (HPDF_PageAttr )page->attr; ++ const char *key; ++ ++ HPDF_PTRACE((" HPDF_Page_GetShadingName\n")); ++ ++ if (!attr->shadings) { ++ HPDF_Dict resources; ++ HPDF_Dict shadings; ++ ++ resources = HPDF_Page_GetInheritableItem (page, "Resources", ++ HPDF_OCLASS_DICT); ++ if (!resources) ++ return NULL; ++ ++ shadings = HPDF_Dict_New (page->mmgr); ++ if (!shadings) ++ return NULL; ++ ++ if (HPDF_Dict_Add (resources, "Shading", shadings) != HPDF_OK) ++ return NULL; ++ ++ attr->shadings = shadings; ++ } ++ ++ /* search shading-object from shading-resource */ ++ key = HPDF_Dict_GetKeyByObj (attr->shadings, shading); ++ if (!key) { ++ /* if the shading is not registered in shadings resource, register ++ * to shadings resource. ++ */ ++ char shading_str[HPDF_LIMIT_MAX_NAME_LEN + 1]; ++ char *ptr; ++ char *end_ptr = shading_str + HPDF_LIMIT_MAX_NAME_LEN; ++ ++ ptr = (char *)HPDF_StrCpy (shading_str, "Sh", end_ptr); ++ HPDF_IToA (ptr, attr->shadings->list->count, end_ptr); ++ ++ if (HPDF_Dict_Add (attr->shadings, shading_str, shading) != HPDF_OK) ++ return NULL; ++ ++ key = HPDF_Dict_GetKeyByObj (attr->shadings, shading); ++ } ++ ++ return key; ++} + + static HPDF_STATUS + AddAnnotation (HPDF_Page page, +diff --git a/src/hpdf_shading.c b/src/hpdf_shading.c +new file mode 100644 +index 0000000..53204c0 +--- /dev/null ++++ b/src/hpdf_shading.c +@@ -0,0 +1,231 @@ ++/* ++ * << Haru Free PDF Library >> -- hpdf_shading.c ++ * ++ * URL: http://libharu.org ++ * ++ * Copyright (c) 1999-2006 Takeshi Kanno ++ * Copyright (c) 2007-2009 Antony Dovgal ++ * Copyright (c) 2017 Kitware ++ * ++ * Permission to use, copy, modify, distribute and sell this software ++ * and its documentation for any purpose is hereby granted without fee, ++ * provided that the above copyright notice appear in all copies and ++ * that both that copyright notice and this permission notice appear ++ * in supporting documentation. ++ * It is provided "as is" without express or implied warranty. ++ * ++ */ ++ ++#include "hpdf.h" ++#include "hpdf_utils.h" ++ ++#include "assert.h" ++ ++typedef struct _RGBVertex ++{ ++ HPDF_UINT8 EdgeFlag; ++ HPDF_UINT32 X; ++ HPDF_UINT32 Y; ++ HPDF_UINT8 RGB[3]; ++} RGBVertex; ++ ++static const char *COL_CMYK = "DeviceCMYK"; ++static const char *COL_RGB = "DeviceRGB"; ++static const char *COL_GRAY = "DeviceGray"; ++ ++/* bbox is filled with xMin, xMax, yMin, yMax */ ++static HPDF_BOOL _GetDecodeArrayVertexValues(HPDF_Shading shading, ++ HPDF_REAL *bbox) ++{ ++ HPDF_Array decodeArray; ++ HPDF_Real r; ++ int i; ++ ++ if (!shading) { ++ return HPDF_FALSE; ++ } ++ ++ decodeArray = (HPDF_Array)(HPDF_Dict_GetItem(shading, "Decode", ++ HPDF_OCLASS_ARRAY)); ++ if (!decodeArray) { ++ return HPDF_FALSE; ++ } ++ ++ for (i = 0; i < 4; ++i) ++ { ++ r = HPDF_Array_GetItem(decodeArray, i, HPDF_OCLASS_REAL); ++ if (!r) { ++ return HPDF_FALSE; ++ } ++ ++ bbox[i] = r->value; ++ } ++ ++ return HPDF_TRUE; ++} ++ ++static void UINT32Swap (HPDF_UINT32 *value) ++{ ++ HPDF_BYTE b[4]; ++ ++ HPDF_MemCpy (b, (HPDF_BYTE *)value, 4); ++ *value = (HPDF_UINT32)((HPDF_UINT32)b[0] << 24 | ++ (HPDF_UINT32)b[1] << 16 | ++ (HPDF_UINT32)b[2] << 8 | ++ (HPDF_UINT32)b[3]); ++} ++ ++/* Encode a position coordinate for writing */ ++static HPDF_UINT32 _EncodeValue(HPDF_REAL x, HPDF_REAL xMin, HPDF_REAL xMax) ++{ ++ HPDF_DOUBLE norm = (x - xMin) / (xMax - xMin); ++ HPDF_DOUBLE max = (HPDF_DOUBLE)(0xFFFFFFFF); ++ HPDF_UINT32 enc = (HPDF_UINT32)(norm * max); ++ UINT32Swap(&enc); ++ return enc; ++} ++ ++HPDF_EXPORT(HPDF_Shading) ++HPDF_Shading_New (HPDF_Doc pdf, ++ HPDF_ShadingType type, ++ HPDF_ColorSpace colorSpace, ++ HPDF_REAL xMin, HPDF_REAL xMax, ++ HPDF_REAL yMin, HPDF_REAL yMax) ++{ ++ HPDF_Shading shading; ++ HPDF_Array decodeArray; ++ HPDF_STATUS ret = HPDF_OK; ++ int i; ++ ++ HPDF_PTRACE((" HPDF_Shading_New\n")); ++ ++ if (!HPDF_HasDoc(pdf)) { ++ return NULL; ++ } ++ ++ /* Validate shading type: */ ++ switch (type) ++ { ++ case HPDF_SHADING_FREE_FORM_TRIANGLE_MESH: ++ break; ++ ++ default: ++ HPDF_SetError (pdf->mmgr->error, HPDF_INVALID_SHADING_TYPE, 0); ++ return NULL; ++ } ++ ++ decodeArray = HPDF_Array_New(pdf->mmgr); ++ if (!decodeArray) { ++ return NULL; ++ } ++ ++ /* X-range */ ++ ret += HPDF_Array_AddReal(decodeArray, xMin); ++ ret += HPDF_Array_AddReal(decodeArray, xMax); ++ ++ /* Y-range */ ++ ret += HPDF_Array_AddReal(decodeArray, yMin); ++ ret += HPDF_Array_AddReal(decodeArray, yMax); ++ ++ const char *colName = NULL; ++ switch (colorSpace) { ++ case HPDF_CS_DEVICE_RGB: ++ colName = COL_RGB; ++ for (i = 0; i < 3; ++i) { ++ ret += HPDF_Array_AddReal(decodeArray, 0.0); ++ ret += HPDF_Array_AddReal(decodeArray, 1.0); ++ } ++ break; ++ ++ default: ++ HPDF_SetError(pdf->mmgr->error, HPDF_INVALID_COLOR_SPACE, 0); ++ return NULL; ++ } ++ ++ if (ret != HPDF_OK) { ++ return NULL; ++ } ++ ++ shading = HPDF_DictStream_New(pdf->mmgr, pdf->xref); ++ if (!shading) { ++ return NULL; ++ } ++ ++ shading->header.obj_class |= HPDF_OSUBCLASS_SHADING; ++ ret += HPDF_Dict_AddNumber(shading, "ShadingType", type); ++ ret += HPDF_Dict_AddName(shading, "ColorSpace", colName); ++ ++ switch (type) ++ { ++ case HPDF_SHADING_FREE_FORM_TRIANGLE_MESH: ++ ret += HPDF_Dict_AddNumber(shading, "BitsPerCoordinate", 32); ++ ret += HPDF_Dict_AddNumber(shading, "BitsPerComponent", 8); ++ ret += HPDF_Dict_AddNumber(shading, "BitsPerFlag", 8); ++ ret += HPDF_Dict_Add(shading, "Decode", decodeArray); ++ break; ++ ++ default: ++ HPDF_SetError (pdf->mmgr->error, HPDF_INVALID_SHADING_TYPE, 0); ++ return NULL; ++ } ++ ++ if (ret != HPDF_OK) { ++ return NULL; ++ } ++ ++ return shading; ++} ++ ++HPDF_EXPORT(HPDF_STATUS) ++HPDF_Shading_AddVertexRGB(HPDF_Shading shading, ++ HPDF_Shading_FreeFormTriangleMeshEdgeFlag edgeFlag, ++ HPDF_REAL x, HPDF_REAL y, ++ HPDF_UINT8 r, HPDF_UINT8 g, HPDF_UINT8 b) ++{ ++ HPDF_STATUS ret = HPDF_OK; ++ RGBVertex vert; ++ float bbox[4]; ++ ++ HPDF_PTRACE((" HPDF_Shading_AddVertexRGB\n")); ++ ++ if (!shading) { ++ return HPDF_INVALID_OBJECT; ++ } ++ ++ if (_GetDecodeArrayVertexValues(shading, bbox) != HPDF_TRUE) { ++ return HPDF_SetError(shading->error, HPDF_INVALID_OBJECT, 0); ++ } ++ ++ vert.EdgeFlag = (HPDF_UINT8)edgeFlag; ++ vert.X = _EncodeValue(x, bbox[0], bbox[1]); ++ vert.Y = _EncodeValue(y, bbox[2], bbox[3]); ++ vert.RGB[0] = r; ++ vert.RGB[1] = g; ++ vert.RGB[2] = b; ++ ++ ret = HPDF_Stream_Write(shading->stream, ++ (HPDF_BYTE*)(&vert.EdgeFlag), sizeof(vert.EdgeFlag)); ++ if (ret != HPDF_OK) ++ { ++ return ret; ++ } ++ ++ ret = HPDF_Stream_Write(shading->stream, ++ (HPDF_BYTE*)(&vert.X), sizeof(vert.X)); ++ if (ret != HPDF_OK) ++ { ++ return ret; ++ } ++ ++ ret = HPDF_Stream_Write(shading->stream, ++ (HPDF_BYTE*)(&vert.Y), sizeof(vert.Y)); ++ if (ret != HPDF_OK) ++ { ++ return ret; ++ } ++ ++ ret = HPDF_Stream_Write(shading->stream, ++ (HPDF_BYTE*)(&vert.RGB), sizeof(vert.RGB)); ++ ++ return ret; ++} diff --git a/recipe/0003-improve-small-number-writing-in-HPDF-FToA.patch b/recipe/0003-improve-small-number-writing-in-HPDF-FToA.patch new file mode 100644 index 0000000..ec736e5 --- /dev/null +++ b/recipe/0003-improve-small-number-writing-in-HPDF-FToA.patch @@ -0,0 +1,94 @@ +From fb11e6913f9da9ae350befa6deb560c10ac0afcd Mon Sep 17 00:00:00 2001 +From: Allison Vacanti +Date: Thu, 4 Oct 2018 13:12:01 -0400 +Subject: [PATCH] Improve small number writing in HPDF_FToA. + +This was truncating all numbers at 1e-5, now it ensures that 5 +significant figures will always be written for values > 1e-20. +--- + include/hpdf_consts.h | 2 +- + include/hpdf_types.h | 6 ++++++ + src/hpdf_utils.c | 23 ++++++++++++++++++++--- + 3 files changed, 27 insertions(+), 4 deletions(-) + +diff --git a/include/hpdf_consts.h b/include/hpdf_consts.h +index 2dbf396..d874f7f 100644 +--- a/include/hpdf_consts.h ++++ b/include/hpdf_consts.h +@@ -32,7 +32,7 @@ + /* buffer size which is required when we convert to character string. */ + #define HPDF_TMP_BUF_SIZ 512 + #define HPDF_SHORT_BUF_SIZ 32 +-#define HPDF_REAL_LEN 11 ++#define HPDF_REAL_LEN 64 + #define HPDF_INT_LEN 11 + #define HPDF_TEXT_DEFAULT_LEN 256 + #define HPDF_UNICODE_HEADER_LEN 2 +diff --git a/include/hpdf_types.h b/include/hpdf_types.h +index a35fe8f..ce5cbd7 100644 +--- a/include/hpdf_types.h ++++ b/include/hpdf_types.h +@@ -45,6 +45,12 @@ typedef signed int HPDF_INT; + typedef unsigned int HPDF_UINT; + + ++/* 64bit integer types ++ */ ++typedef signed long long HPDF_INT64; ++typedef unsigned long long HPDF_UINT64; ++ ++ + /* 32bit integer types + */ + typedef signed int HPDF_INT32; +diff --git a/src/hpdf_utils.c b/src/hpdf_utils.c +index 728da5a..6e9a8b7 100644 +--- a/src/hpdf_utils.c ++++ b/src/hpdf_utils.c +@@ -15,6 +15,7 @@ + * + */ + ++#include + #include + #include "hpdf_utils.h" + #include "hpdf_consts.h" +@@ -188,6 +189,10 @@ HPDF_FToA (char *s, + char* sptr = s; + char* t; + HPDF_UINT32 i; ++ HPDF_UINT32 prec; ++ HPDF_INT32 logVal; ++ HPDF_REAL roundInc; ++ HPDF_INT64 fShift; + + if (val > HPDF_LIMIT_MAX_REAL) + val = HPDF_LIMIT_MAX_REAL; +@@ -203,12 +208,24 @@ HPDF_FToA (char *s, + val = -val; + } + ++ /* Compute the decimal precision to write at least 5 significant figures */ ++ logVal = (HPDF_INT32)(val > 1e-20 ? log10(val) : 0.); ++ if (logVal >= 0) { ++ prec = 5; ++ } ++ else { ++ prec = -logVal + 5; ++ } ++ ++ roundInc = 0.5 * (1. / pow((HPDF_REAL)10, (HPDF_REAL)prec)); ++ fShift = (HPDF_INT64)pow((HPDF_REAL)10, (HPDF_REAL)prec); ++ + /* separate an integer part and a decimal part. */ +- int_val = (HPDF_INT32)(val + 0.000005); +- fpart_val = (HPDF_INT32)((HPDF_REAL)(val - int_val + 0.000005) * 100000); ++ int_val = (HPDF_INT64)(val + roundInc); ++ fpart_val = (HPDF_INT64)((HPDF_REAL)(val - int_val + roundInc) * fShift); + + /* process decimal part */ +- for (i = 0; i < 5; i++) { ++ for (i = 0; i < prec; i++) { + *t = (char)((char)(fpart_val % 10) + '0'); + fpart_val /= 10; + t--; diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 47034e8..66aed06 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -10,9 +10,11 @@ source: sha256: 8f9e68cc5d5f7d53d1bc61a1ed876add1faf4f91070dbc360d8b259f46d9a4d2 patches: - 0001-skip-installing-if-directory.patch + - 0002-add-support-for-free-form.patch + - 0003-improve-small-number-writing-in-HPDF-FToA.patch build: - number: 0 + number: 1 requirements: build: From 9d5843cd82158d50831d491f0ffbea6c8d59e159 Mon Sep 17 00:00:00 2001 From: conda-forge-linter Date: Tue, 5 May 2020 18:13:20 +0000 Subject: [PATCH 2/2] MNT: Re-rendered with conda-build 3.19.2, conda-smithy 3.7.0, and conda-forge-pinning 2020.05.04.19.59.17 --- .azure-pipelines/azure-pipelines-osx.yml | 58 ++---------------------- .azure-pipelines/azure-pipelines-win.yml | 19 ++++---- .ci_support/win_.yaml | 2 +- .scripts/build_steps.sh | 5 +- .scripts/run_docker_build.sh | 4 +- .scripts/run_osx_build.sh | 55 ++++++++++++++++++++++ 6 files changed, 77 insertions(+), 66 deletions(-) create mode 100755 .scripts/run_osx_build.sh diff --git a/.azure-pipelines/azure-pipelines-osx.yml b/.azure-pipelines/azure-pipelines-osx.yml index ea0a1cf..1971661 100755 --- a/.azure-pipelines/azure-pipelines-osx.yml +++ b/.azure-pipelines/azure-pipelines-osx.yml @@ -17,60 +17,10 @@ jobs: steps: # TODO: Fast finish on azure pipelines? - script: | - echo "Fast Finish" - - - - script: | - echo "Removing homebrew from Azure to avoid conflicts." - curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall > ~/uninstall_homebrew - chmod +x ~/uninstall_homebrew - ~/uninstall_homebrew -fq - rm ~/uninstall_homebrew - displayName: Remove homebrew - - - bash: | - echo "##vso[task.prependpath]$CONDA/bin" - sudo chown -R $USER $CONDA - displayName: Add conda to PATH - - - script: | - source activate base - conda install -n base -c conda-forge --quiet --yes conda-forge-ci-setup=2 conda-build - displayName: 'Add conda-forge-ci-setup=2' - - - script: | - source activate base - echo "Configuring conda." - - setup_conda_rc ./ "./recipe" ./.ci_support/${CONFIG}.yaml export CI=azure - source run_conda_forge_build_setup - conda update --yes --quiet --override-channels -c conda-forge -c defaults --all - env: { - OSX_FORCE_SDK_DOWNLOAD: "1" - } - displayName: Configure conda and conda-build - - - script: | - source activate base - mangle_compiler ./ "./recipe" ./.ci_support/${CONFIG}.yaml - displayName: Mangle compiler - - - script: | - source activate base - make_build_number ./ "./recipe" ./.ci_support/${CONFIG}.yaml - displayName: Generate build number clobber file - - - script: | - source activate base - conda build "./recipe" -m ./.ci_support/${CONFIG}.yaml --clobber-file ./.ci_support/clobber_${CONFIG}.yaml - displayName: Build recipe - - - script: | - source activate base + export OSX_FORCE_SDK_DOWNLOAD="1" export GIT_BRANCH=$BUILD_SOURCEBRANCHNAME - upload_package ./ "./recipe" ./.ci_support/${CONFIG}.yaml - displayName: Upload package + ./.scripts/run_osx_build.sh + displayName: Run OSX build env: - BINSTAR_TOKEN: $(BINSTAR_TOKEN) - condition: and(succeeded(), not(eq(variables['UPLOAD_PACKAGES'], 'False'))) \ No newline at end of file + BINSTAR_TOKEN: $(BINSTAR_TOKEN) \ No newline at end of file diff --git a/.azure-pipelines/azure-pipelines-win.yml b/.azure-pipelines/azure-pipelines-win.yml index dfb347c..5b0bfd2 100755 --- a/.azure-pipelines/azure-pipelines-win.yml +++ b/.azure-pipelines/azure-pipelines-win.yml @@ -56,30 +56,31 @@ jobs: - task: CondaEnvironment@1 inputs: - packageSpecs: 'python=3.6 conda-build conda conda-forge::conda-forge-ci-setup=2' # Optional + packageSpecs: 'python=3.6 conda-build conda conda-forge::conda-forge-ci-setup=3 pip' # Optional installOptions: "-c conda-forge" updateConda: true displayName: Install conda-build and activate environment - script: set PYTHONUNBUFFERED=1 + displayName: Set PYTHONUNBUFFERED # Configure the VM - - script: setup_conda_rc .\ ".\recipe" .\.ci_support\%CONFIG%.yaml + - script: | + call activate base + setup_conda_rc .\ ".\recipe" .\.ci_support\%CONFIG%.yaml + displayName: conda-forge CI setup # Configure the VM. - script: | set "CI=azure" + call activate base run_conda_forge_build_setup displayName: conda-forge build setup - - script: | - rmdir C:\strawberry /s /q - continueOnError: true - displayName: remove strawberryperl - # Special cased version setting some more things! - script: | + call activate base conda.exe build "recipe" -m .ci_support\%CONFIG%.yaml displayName: Build recipe (vs2008) env: @@ -88,6 +89,7 @@ jobs: condition: contains(variables['CONFIG'], 'vs2008') - script: | + call activate base conda.exe build "recipe" -m .ci_support\%CONFIG%.yaml displayName: Build recipe env: @@ -96,7 +98,8 @@ jobs: - script: | set "GIT_BRANCH=%BUILD_SOURCEBRANCHNAME%" - upload_package .\ ".\recipe" .ci_support\%CONFIG%.yaml + call activate base + upload_package .\ ".\recipe" .ci_support\%CONFIG%.yaml displayName: Upload package env: BINSTAR_TOKEN: $(BINSTAR_TOKEN) diff --git a/.ci_support/win_.yaml b/.ci_support/win_.yaml index 19a2e7e..879f75b 100644 --- a/.ci_support/win_.yaml +++ b/.ci_support/win_.yaml @@ -1,5 +1,5 @@ c_compiler: -- vs2015 +- vs2017 channel_sources: - conda-forge,defaults channel_targets: diff --git a/.scripts/build_steps.sh b/.scripts/build_steps.sh index 8a4af44..5b14787 100755 --- a/.scripts/build_steps.sh +++ b/.scripts/build_steps.sh @@ -19,7 +19,8 @@ conda-build: CONDARC -conda install --yes --quiet conda-forge-ci-setup=2 conda-build -c conda-forge +conda install --yes --quiet conda-forge-ci-setup=3 conda-build pip -c conda-forge + # set up the condarc setup_conda_rc "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}" @@ -33,7 +34,7 @@ conda build "${RECIPE_ROOT}" -m "${CI_SUPPORT}/${CONFIG}.yaml" \ --clobber-file "${CI_SUPPORT}/clobber_${CONFIG}.yaml" if [[ "${UPLOAD_PACKAGES}" != "False" ]]; then - upload_package "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}" + upload_package "${FEEDSTOCK_ROOT}" "${RECIPE_ROOT}" "${CONFIG_FILE}" fi touch "${FEEDSTOCK_ROOT}/build_artifacts/conda-forge-build-done-${CONFIG}" \ No newline at end of file diff --git a/.scripts/run_docker_build.sh b/.scripts/run_docker_build.sh index 066a857..253723c 100755 --- a/.scripts/run_docker_build.sh +++ b/.scripts/run_docker_build.sh @@ -52,8 +52,10 @@ mkdir -p "$ARTIFACTS" DONE_CANARY="$ARTIFACTS/conda-forge-build-done-${CONFIG}" rm -f "$DONE_CANARY" +# Allow people to specify extra default arguments to `docker run` (e.g. `--rm`) +DOCKER_RUN_ARGS="${CONDA_FORGE_DOCKER_RUN_ARGS}" if [ -z "${CI}" ]; then - DOCKER_RUN_ARGS="-it " + DOCKER_RUN_ARGS="-it ${DOCKER_RUN_ARGS}" fi export UPLOAD_PACKAGES="${UPLOAD_PACKAGES:-True}" diff --git a/.scripts/run_osx_build.sh b/.scripts/run_osx_build.sh new file mode 100755 index 0000000..775799b --- /dev/null +++ b/.scripts/run_osx_build.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set -x + +echo -e "\n\nInstalling a fresh version of Miniforge." +if [[ ${CI} == "travis" ]]; then + echo -en 'travis_fold:start:install_miniforge\\r' +fi +MINIFORGE_URL="https://github.com/conda-forge/miniforge/releases/latest/download" +MINIFORGE_FILE="Miniforge3-MacOSX-x86_64.sh" +curl -L -O "${MINIFORGE_URL}/${MINIFORGE_FILE}" +bash $MINIFORGE_FILE -b +if [[ ${CI} == "travis" ]]; then + echo -en 'travis_fold:end:install_miniforge\\r' +fi + +echo -e "\n\nConfiguring conda." +if [[ ${CI} == "travis" ]]; then + echo -en 'travis_fold:start:configure_conda\\r' +fi + +source ${HOME}/miniforge3/etc/profile.d/conda.sh +conda activate base + +echo -e "\n\nInstalling conda-forge-ci-setup=3 and conda-build." +conda install -n base --quiet --yes conda-forge-ci-setup=3 conda-build pip + + + +echo -e "\n\nSetting up the condarc and mangling the compiler." +setup_conda_rc ./ ./recipe ./.ci_support/${CONFIG}.yaml +mangle_compiler ./ ./recipe .ci_support/${CONFIG}.yaml + +echo -e "\n\nMangling homebrew in the CI to avoid conflicts." +/usr/bin/sudo mangle_homebrew +/usr/bin/sudo -k + +echo -e "\n\nRunning the build setup script." +source run_conda_forge_build_setup + + +if [[ ${CI} == "travis" ]]; then + echo -en 'travis_fold:end:configure_conda\\r' +fi + +set -e + +echo -e "\n\nMaking the build clobber file and running the build." +make_build_number ./ ./recipe ./.ci_support/${CONFIG}.yaml +conda build ./recipe -m ./.ci_support/${CONFIG}.yaml --clobber-file ./.ci_support/clobber_${CONFIG}.yaml + +if [[ "${UPLOAD_PACKAGES}" != "False" ]]; then + echo -e "\n\nUploading the packages." + upload_package ./ ./recipe ./.ci_support/${CONFIG}.yaml +fi \ No newline at end of file