int FontMatchInfoObject:: addToString(const char *&str, int &strLen, int &strMaxLen, const char value) { if ((strMaxLen - strLen) <= 1) { str = (char *)WF_REALLOC((char*)str,strMaxLen + MY_BLOCK_SIZE); if (str == NULL) return 0; strMaxLen += MY_BLOCK_SIZE; } *((char *)(str+strLen)) = value; strLen++; *((char *)(str+strLen)) = '\0'; return strLen; }
void MergeSizes(jdouble * &oldSizes, int &oldLenMax, jdouble *newSizes) { int newlen = 0; if (!newSizes) { return; } while (newSizes[newlen] >= 0) { int i = 0; int found = 0; if (oldSizes == NULL) { oldSizes = (jdouble *) WF_ALLOC(sizeof(*oldSizes) * INTS_AT_A_TIME); if (!oldSizes) return; oldSizes[0] = -1; oldLenMax = INTS_AT_A_TIME; } for (;oldSizes[i] >= 0; i++) { if (newSizes[newlen] == oldSizes[i]) { found++; break; } } if (!found) { // Add newSizes[newlen] to oldSizes if (i >= oldLenMax-1) { // Need more memory. oldSizes = (jdouble *) WF_REALLOC(oldSizes, sizeof(*oldSizes) * (oldLenMax + INTS_AT_A_TIME)); if (!oldSizes) return; oldLenMax += INTS_AT_A_TIME; } oldSizes[i++] = newSizes[newlen]; oldSizes[i++] = -1; } newlen++; } }
int wf_addToString(char **str, int *len, int *maxlen, const char *s) { if (!s || !*s) { return (0); } if (!maxlen || !str) { // Invalid params. return (-1); } int slen = strlen(s); int curlen = 0; if (!len) { curlen = strlen(*str); } else { curlen = *len; } if (curlen + slen + 1 > *maxlen) { int newlen = WF_ROUND_INT(curlen+slen+1, WF_STRING_ALLOCATION_STEP); *str = (char *)WF_REALLOC(*str, sizeof(char)*newlen); if (!*str) { // No memory return (-1); } *maxlen = newlen; } memcpy((*str)+curlen, s, slen+1); if (len) { *len += slen; } return (0); }
int /*ARGSUSED*/ wfSizesList::addRf(struct nfrf *rf) { // We are changing logic here. All we are going to do is to // add the rf in the list of rf's that were created here. // size is not used. if (rfcount + 1 > maxrfcount) { // need more memory if (maxrfcount == 0) { rfs = (struct nfrf **)WF_ALLOC(rfAllocStep * sizeof (*rfs)); } else { rfs = (struct nfrf **) WF_REALLOC(rfs, (maxrfcount+rfAllocStep) * sizeof(*rfs)); } if (!rfs) { // XXX no more memory. things are about to go horribly // wrong. The garbage collection code is banking on this // to be able to keep track of the rfs that were created. return -1; } maxrfcount += rfAllocStep; } rfs[rfcount] = rf; // NOTE: we should not increment the reference count here // This was done so that the rfs will release normally. // If we did increment the refcount, then this rf will // never be released. That is why we have nffbp::RfDone() // to notify us that this rf is going away. // nfrf_addRef((struct nfrf *)rf, NULL); rfcount++; return (0); }
int FontMatchInfoObject:: addToString(const char *&str, int &strLen, int &strMaxLen, const char *value) { int valueLen = 0; if (!value || !*value) { // Use default symbol return (0); } valueLen = strlen(value); while ((strMaxLen - strLen) <= valueLen) { str = (char *)WF_REALLOC((char*)str,strMaxLen + MY_BLOCK_SIZE); if (str == NULL) return 0; strMaxLen += MY_BLOCK_SIZE; } strcpy((char*)(str+strLen), value); strLen += valueLen; return strLen; }