Hi,
        I've taken the liberty of posting your patches to main list for
their views.

I'll take a look at it after 0.7.12 is out.

Cheers!

Martin


---------- Forwarded message ----------
Date: Tue, 21 Nov 2000 08:51:09 +0000 (GMT)
From: F J Franklin <[EMAIL PROTECTED]>
To: Martin Sevior <[EMAIL PROTECTED]>
Subject: Re: some minor postscript fixes

On Sun, 19 Nov 2000, F J Franklin wrote:
> Anyway, then and now, I've been thinking that a much more radical (all
> things being relative) alteration is required; I'll give it a shot
> sometime.

Okay, here it is. I hope it doesn't go against established abiword
programming methodology, however.

This adds a new class in abi/src/af/xap/unix based on UT_Vector,
specifically for creating a vector of document resources, and I modify
xap_UnixPSGenerate.cpp/.h and xap_UnixPSGraphics.cpp accordingly.

It is very problem-specific, which worries me a little, but on the other
hand I have tried to make it easily extensible to other resource types
(should the need for such ever arise).

It's not release critical, and it's certainly not a showstopper, but it's
a bug and I get obsessed easily... :-)

Please let me have your opinion.

Regards, Frank
<[EMAIL PROTECTED]>

Francis James Franklin
[EMAIL PROTECTED]

Diodorus the professor of logic died of shame because he could not at once 
solve a problem put to him in jest by Stilpo.
                                                       --- Pliny the Elder
--- abi/src/af/xap/unix/xap_UnixFont.cpp        Mon Oct 30 18:31:47 2000
+++ abi/src/af/xap/unix/xap_UnixFont.cpp.fjf    Tue Oct 31 09:42:43 2000
@@ -422,7 +422,7 @@
   { 0x00DD, "Yacute" },
   { 0x00DB, "Ucircumflex" },
   { 0x00D9, "Ugrave" },
-  // HELP: What is "Zcaron"?
+  // HELP: What is "Zcaron"? ANS: Z + caron; caron = inverted circumflex
   { 0x00FF, "Ydieresis" },
   { 0x00B3, "threesuperior" },
   { 0x00DA, "Uacute" },
@@ -440,7 +440,7 @@
   { 0x00E5, "aring" },
   { 0x00E4, "adieresis" },
   { 0x00D2, "Ograve" },
-  { 0x00D4, "Ocurcumflex" },
+  { 0x00D4, "Ocircumflex" },
   { 0x00D6, "Odieresis" },
   { 0x00D1, "Ntilde" },
   { 0x00EB, "edieresis" },
@@ -450,7 +450,7 @@
   { 0x00EA, "ecircumflex" },
   { 0x00CC, "Igrave" },
   { 0x00CD, "Iacute" },
-  { 0x00CF, "Idiersis" },
+  { 0x00CF, "Idieresis" },
   { 0x00B0, "degree" },
   { 0x00CA, "Ecircumflex" },
   { 0x002D, "minus" },
@@ -500,7 +500,7 @@
   { 0x00A6, "brokenbar" },
   { 0x00DE, "Thorn" },
   { 0x00C4, "Adieresis" },
-  // HELP: What is "mu"?
+  { 0x00B5, "mu" },
   { 0x0000, NULL }
 };
 
diff -Naur abi/src/af/xap/Makefile abi.fjf/src/af/xap/Makefile
--- abi/src/af/xap/Makefile     Mon Oct 30 21:57:22 2000
+++ abi.fjf/src/af/xap/Makefile Mon Nov 20 19:21:44 2000
@@ -55,7 +55,8 @@
                        $(OBJDIR)/xap_$(ABI_FE)PSParseAFM.$(OBJ_SUFFIX)         \
                        $(OBJDIR)/xap_$(ABI_FE)PSImage.$(OBJ_SUFFIX)            \
                        $(OBJDIR)/xap_$(ABI_FE)PSGraphics.$(OBJ_SUFFIX)         \
-                       $(OBJDIR)/xap_$(ABI_FE)EncodingManager.$(OBJ_SUFFIX)
+                       $(OBJDIR)/xap_$(ABI_FE)EncodingManager.$(OBJ_SUFFIX)    \
+                       $(OBJDIR)/xap_$(ABI_FE)PSRVector.$(OBJ_SUFFIX)
 endif
 
 ifeq ($(ABI_FE), Win32)
diff -Naur abi/src/af/xap/unix/Makefile abi.fjf/src/af/xap/unix/Makefile
--- abi/src/af/xap/unix/Makefile        Mon Nov  6 05:06:59 2000
+++ abi.fjf/src/af/xap/unix/Makefile    Mon Nov 20 18:28:53 2000
@@ -46,7 +46,8 @@
                        xap_UnixPSParseAFM.cpp                  \
                        xap_UnixPSImage.cpp                     \
                        xap_UnixPSGraphics.cpp                  \
-                       xap_UnixEncodingManager.cpp
+                       xap_UnixEncodingManager.cpp             \
+                       xap_UnixPSRVector.cpp
 
 TARGETS=               $(OBJS)
 INCLUDES=              -I/usr/X11R6/include \
diff -Naur abi/src/af/xap/unix/xap_UnixPSGenerate.cpp 
abi.fjf/src/af/xap/unix/xap_UnixPSGenerate.cpp
--- abi/src/af/xap/unix/xap_UnixPSGenerate.cpp  Tue Oct 10 01:39:28 2000
+++ abi.fjf/src/af/xap/unix/xap_UnixPSGenerate.cpp      Mon Nov 20 18:39:39 2000
@@ -170,16 +170,14 @@
                        strcat(buf,"\n");
                        if (!writeBytes(buf))
                                return UT_FALSE;
-                       sprintf(buf,"%%%%+");
+                       sprintf(buf,"%%%%+ %s",argv[k]);
                }
        }
-       bufLen = strlen(buf);
-       if (bufLen > 3)                                         // 3==strlen("%%+")
-       {
-               strcat(buf,"\n");
-               if (!writeBytes(buf))
-                       return UT_FALSE;
-       }
+
+       strcat(buf,"\n");
+       if (!writeBytes(buf))
+               return UT_FALSE;
+
        return UT_TRUE;
 }
 
@@ -208,16 +206,52 @@
                        strcat(buf,"\n");
                        if (!writeBytes(buf))
                                return UT_FALSE;
-                       sprintf(buf,"%%%%+");
+                       sprintf(buf,"%%%%+ %s",psz);
                }
        }
-       bufLen = strlen(buf);
-       if (bufLen > 3)                                         // 3==strlen("%%+")
+
+       strcat(buf,"\n");
+       if (!writeBytes(buf))
+               return UT_FALSE;
+
+       return UT_TRUE;
+}
+
+UT_Bool ps_Generate::documentNeededResources(const XAP_UnixPSRVector * psrVec)
+{
+       // write out a DocumentNeededResources line, possibly with multiple
+       // arguments
+       // we PS-escapify each arg as we output it.
+       // return true if successful.
+       
+       char buf[256];
+       UT_uint32 argc = psrVec->getItemCount();
+       
+       for (UT_uint32 n = 0; n < argc; n++)
        {
+               XAP_UnixPSResource* psr = psrVec->getNthItem(n);
+
+               if (n == 0) strcpy(buf,"%%DocumentNeededResources: ");
+               else strcpy(buf,"%%+ ");
+
+               switch (psr->id)        // TODO: ?? PS-escapify each arg as we output 
+it.
+               {
+               case PSR_FONT:
+                       strcat(buf,"font ");
+                       UT_ASSERT(strlen(psr->psr.font.name)<223);      // unlikely??
+                       strcat(buf,psr->psr.font.name);
+                       break;
+
+               default:
+                       UT_ASSERT(UT_NOT_IMPLEMENTED);
+                       break;
+               }
                strcat(buf,"\n");
+
                if (!writeBytes(buf))
                        return UT_FALSE;
        }
+
        return UT_TRUE;
 }
 
diff -Naur abi/src/af/xap/unix/xap_UnixPSGenerate.h 
abi.fjf/src/af/xap/unix/xap_UnixPSGenerate.h
--- abi/src/af/xap/unix/xap_UnixPSGenerate.h    Sat May 15 22:14:18 1999
+++ abi.fjf/src/af/xap/unix/xap_UnixPSGenerate.h        Mon Nov 20 18:35:17 2000
@@ -24,6 +24,8 @@
 #include "ut_types.h"
 #include "ut_vector.h"
 
+#include "xap_UnixPSRVector.h"
+
 class ps_Generate
 {
 public:
@@ -41,6 +43,7 @@
        UT_Bool         formatComment(const char * szCommentName, const char * 
szArg1);
        UT_Bool         formatComment(const char * szCommentName, const char **argv, 
int argc);
        UT_Bool         formatComment(const char * szCommentName, const UT_Vector * 
pVec);
+       UT_Bool         documentNeededResources(const XAP_UnixPSRVector * psrVec);
 
 protected:
        void            doProtectFromPipe(void);
diff -Naur abi/src/af/xap/unix/xap_UnixPSGraphics.cpp 
abi.fjf/src/af/xap/unix/xap_UnixPSGraphics.cpp
--- abi/src/af/xap/unix/xap_UnixPSGraphics.cpp  Thu Nov  2 05:27:19 2000
+++ abi.fjf/src/af/xap/unix/xap_UnixPSGraphics.cpp      Mon Nov 20 19:30:52 2000
@@ -33,6 +33,7 @@
 #include "xap_UnixPSGraphics.h"
 #include "xap_UnixPSFont.h"
 #include "xap_UnixPSImage.h"
+#include "xap_UnixPSRVector.h"
 
 #include "xap_UnixFont.h"
 #include "xap_UnixFontManager.h"
@@ -667,21 +668,22 @@
 
 void PS_Graphics::_emit_DocumentNeededResources(void)
 {
-       UT_Vector vec;
-       UT_uint32 k;
-       UT_uint32 kLimit = m_vecFontList.getItemCount();
+       XAP_UnixPSRVector vec;
+       XAP_UnixPSResource res;
 
-       for (k=0; k<kLimit; k++)
+// Fonts:
+       res.id = PSR_FONT;
+       UT_uint32 NFonts = m_vecFontList.getItemCount();
+       for (UT_uint32 n = 0; n < NFonts; n++)
        {
-               vec.addItem((void *) "font");
-               PSFont * psf = (PSFont *)m_vecFontList.getNthItem(k);
-               if(!psf->getUnixFont()->is_CJK_font())
-                   vec.addItem(psf->getMetricsData()->gfi->fontName);
+               PSFont* psf = (PSFont*)m_vecFontList.getNthItem(n);
+               res.psr.font.name = (const char*)psf->getMetricsData()->gfi->fontName;
+               vec.addIfUnique(&res);
        }
 
-       // TODO add any other resources here
+// TODO: other resources:
        
-       m_ps->formatComment("DocumentNeededResources",&vec);
+       m_ps->documentNeededResources(&vec);
 }
 
 void PS_Graphics::_emit_IncludeResource(void)
diff -Naur abi/src/af/xap/unix/xap_UnixPSRVector.cpp 
abi.fjf/src/af/xap/unix/xap_UnixPSRVector.cpp
--- abi/src/af/xap/unix/xap_UnixPSRVector.cpp   Thu Jan  1 01:00:00 1970
+++ abi.fjf/src/af/xap/unix/xap_UnixPSRVector.cpp       Mon Nov 20 19:21:53 2000
@@ -0,0 +1,164 @@
+/* AbiSource Program Utilities
+ * Copyright (C) 1998 AbiSource, Inc.
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
+ * 02111-1307, USA.
+ */
+ 
+
+
+#include <stdlib.h>
+#include <string.h>
+
+// TODO change the 'int' types to 'UT_[su]int32' whichever is appropriate.
+
+#include "ut_types.h"
+#include "ut_assert.h"
+
+#include "xap_UnixPSRVector.h"
+
+XAP_UnixPSRVector::XAP_UnixPSRVector()
+{
+       m_iCutoffDouble = 64;                   // TODO make this tunable?
+       m_iPostCutoffIncrement = 8;
+       m_iCount = 0;
+       m_iSpace = 0;
+       m_pEntries = 0;
+}
+
+void XAP_UnixPSRVector::clear()
+{
+       m_iCount = 0;
+       m_iSpace = 0;
+       FREEP(m_pEntries);
+       m_pEntries = 0;
+}
+
+XAP_UnixPSRVector::~XAP_UnixPSRVector()
+{
+       FREEP(m_pEntries);
+}
+
+UT_uint32 XAP_UnixPSRVector::calcNewSpace(void)
+{
+       if (m_iSpace < m_iCutoffDouble)
+       {
+               if (m_iSpace > 0)
+               {
+                       return m_iSpace * 2;
+               }
+               else
+               {
+                       return m_iPostCutoffIncrement;
+               }
+       }
+       else
+       {
+               return m_iSpace + m_iPostCutoffIncrement;
+       }
+}
+
+UT_uint32 XAP_UnixPSRVector::getItemCount() const
+{
+       return m_iCount;
+}
+
+UT_sint32 XAP_UnixPSRVector::grow(UT_uint32 ndx)
+{
+       UT_uint32 new_iSpace = calcNewSpace();
+       if (new_iSpace < ndx)
+       {
+               new_iSpace = ndx;
+       }
+
+       XAP_UnixPSResource* new_pEntries = (XAP_UnixPSResource*) calloc(new_iSpace, 
+sizeof(XAP_UnixPSResource));
+       if (!new_pEntries)
+       {
+               return -1;
+       }
+
+       if (m_pEntries && (m_iCount > 0))
+       {
+               for (UT_uint32 i=0; i<m_iCount; i++)
+               {
+                       new_pEntries[i] = m_pEntries[i];
+               }
+
+               FREEP(m_pEntries);
+       }
+
+       m_iSpace = new_iSpace;
+       m_pEntries = new_pEntries;
+
+       return 0;
+}
+
+UT_sint32 XAP_UnixPSRVector::addItem(XAP_UnixPSResource* psr)
+{
+       UT_ASSERT(psr);
+
+       if ((m_iCount+1) > m_iSpace)
+       {
+               UT_sint32 err = grow(0);
+               if (err)
+               {
+                       return err;
+               }
+       }
+
+       m_pEntries[m_iCount++] = (*psr);
+
+       return 0;
+}
+
+UT_sint32 XAP_UnixPSRVector::addIfUnique(XAP_UnixPSResource* psr)
+{
+       UT_ASSERT(psr);
+
+       UT_Bool preexistent = UT_FALSE;
+
+       for (UT_uint32 n = 0; n < m_iCount; n++)
+       {
+               if (m_pEntries[n].id == psr->id)
+               {
+                       switch (psr->id)
+                       {
+                       case PSR_FONT:
+                               if (strcmp 
+(psr->psr.font.name,m_pEntries[n].psr.font.name) == 0)
+                               {
+                                       preexistent = UT_TRUE;
+                               }
+                               break;
+
+                       default:
+                               UT_ASSERT(UT_NOT_IMPLEMENTED);
+                               break;
+                       }
+               }
+               if (preexistent) break;
+       }
+       if (preexistent) return 0;
+
+       return addItem(psr);
+}
+
+XAP_UnixPSResource* XAP_UnixPSRVector::getNthItem(UT_uint32 n) const
+{
+       UT_ASSERT(m_pEntries);
+       UT_ASSERT(m_iCount > 0);
+       UT_ASSERT(n<m_iCount);
+
+       return m_pEntries + n;
+}
diff -Naur abi/src/af/xap/unix/xap_UnixPSRVector.h 
abi.fjf/src/af/xap/unix/xap_UnixPSRVector.h
--- abi/src/af/xap/unix/xap_UnixPSRVector.h     Thu Jan  1 01:00:00 1970
+++ abi.fjf/src/af/xap/unix/xap_UnixPSRVector.h Mon Nov 20 18:27:27 2000
@@ -0,0 +1,75 @@
+/* AbiSource Program Utilities
+ * Copyright (C) 1998 AbiSource, Inc.
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  
+ * 02111-1307, USA.
+ */
+ 
+#ifndef XAP_UNIXPSRVECTOR_H
+#define XAP_UNIXPSRVECTOR_H
+
+#include "ut_types.h"
+#include "ut_assert.h"
+
+// TODO change the 'int' types to 'UT_[su]int32' whichever is appropriate.
+
+// ----------------------------------------------------------------
+/*
+       The following class is a simple, portable implementation of a vector
+       for postscript resources.
+
+       Following in Mozilla's footsteps, we don't use STL because templates 
+       are not yet portable enough for our needs.  (Same goes for exceptions
+       and namespaces, BTW.)
+*/
+
+typedef enum _xap_unixpsresourceid { PSR_FONT } XAP_UnixPSResourceID;
+
+typedef struct _xap_unixpsresource
+{      XAP_UnixPSResourceID id;
+       union
+       {       struct
+               {       const char* name;
+               } font;
+       } psr;
+} XAP_UnixPSResource;
+
+class XAP_UnixPSRVector
+{
+public:
+       XAP_UnixPSRVector();
+       ~XAP_UnixPSRVector();
+
+       void                    clear();
+
+       UT_sint32               addItem(XAP_UnixPSResource*);
+       UT_sint32               addIfUnique(XAP_UnixPSResource*);
+
+       XAP_UnixPSResource*     getNthItem(UT_uint32 n) const;
+       UT_uint32               getItemCount() const;
+
+protected:
+       UT_uint32               calcNewSpace();
+       UT_sint32               grow(UT_uint32);
+       
+       XAP_UnixPSResource*     m_pEntries;
+
+       UT_uint32               m_iCount;
+       UT_uint32               m_iSpace;
+       UT_uint32               m_iCutoffDouble;
+       UT_uint32               m_iPostCutoffIncrement;
+};
+
+#endif /* XAP_UNIXPSRVECTOR_H */

Reply via email to