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; kgetUnixFont()->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 +#include + +// 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_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