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 /*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); }
// // Font stream handler. // This will be called by netlib to when a stream of type FO_FONT // is available. // extern "C" NET_StreamClass* /*ARGSUSED*/ wfNewStream(FO_Present_Types format_out, void* client_data, URL_Struct* urls, MWContext* cx) { struct nffbc *fbc = (struct nffbc *) client_data; struct wf_new_stream_data *inData = (struct wf_new_stream_data *) urls->fe_data; cfbImpl *oimpl = cfb2cfbImpl(fbc); FontBrokerObject *fbobj = (FontBrokerObject *)oimpl->object; const char *mimetype = fbobj->GetMimetype(urls->content_type, urls->address); if (!mimetype || !*mimetype) { return (NULL); } WF_TRACEMSG(("NF: Looking for mimetype: %s.", mimetype)); NET_StreamClass *netStream = NULL; // Find which font Displayer implements the mimetype struct wfListElement *tmp = fbobj->fpPeers.head; for(; tmp; tmp = tmp->next) { FontDisplayerPeerObject *fpp = (FontDisplayerPeerObject *) tmp->item; if (fpp->isMimetypeEnabled(mimetype) > 0) { // Get the font Displayer stream handle WF_TRACEMSG(("NF: fppeer %s supports mimetype %s.", fpp->name(), mimetype)); struct nfstrm *fpStream = fpp->CreateFontStreamHandler(inData->rc, inData->url_of_page); if (!fpStream) { // Error. Cannot create stream from Font Displayer. // We will cycle through other Displayers to see if we can // find any other font Displayer who can service us. WF_TRACEMSG(("NF: fppeer %s cannot create fpStream. " "Continuing...", fpp->name())); fpp = NULL; continue; } // Create a libnet stream netStream = (NET_StreamClass *) WF_ALLOC(sizeof(NET_StreamClass)); if (!netStream) { // Error. No point continuing. WF_TRACEMSG(("NF: Error: Cannot create net stream. No memory.")); nfstrm_release(fpStream, NULL); break; } // Create our stream data object struct stream_data *wfStream = new stream_data; if (!wfStream) { WF_TRACEMSG(("NF: Error: No memory to allocate stream_data.")); nfstrm_release(fpStream, NULL); delete netStream; netStream = NULL; break; } // Fill our stream data wfStream->urls = urls; nffbc_addRef(fbc, NULL); wfStream->fbc = fbc; // fpstream was created here. So no need to addref it as // the creation process would already have incremented the // refcount. //nfstrm_addRef(fpStream, NULL); wfStream->fpStream = fpStream; // Tell the wffpPeer about this new stream fpp->StreamCreated(fpStream); nfdoer_addRef(inData->observer, NULL); wfStream->observer = inData->observer; nff_addRef(inData->f, NULL); wfStream->f = inData->f; wfStream->fpPeer = fpp; // Fill libnet stream netStream->name = "Font Broker"; netStream->abort = wfAbort; netStream->complete = wfComplete; netStream->put_block = (MKStreamWriteFunc)wfWrite; netStream->is_write_ready = wfWriteReady; netStream->data_object = (void *)wfStream; netStream->window_id = cx; break; } } // Cleanup our wf_new_stream_data that was passed in nfdoer_release(inData->observer, NULL); nff_release(inData->f, NULL); nfrc_release(inData->rc, NULL); if (inData->url_of_page) { delete inData->url_of_page; inData->url_of_page = NULL; } delete inData; return (netStream); }