void TestGooString::testInsert() { { GooString goo; goo.insert(0, "."); goo.insert(0, "This is a very long long test string"); QCOMPARE(goo.getCString(), "This is a very long long test string."); } { GooString goo; goo.insert(0, "second-part-third-part"); goo.insert(0, "first-part-"); QCOMPARE(goo.getCString(), "first-part-second-part-third-part"); } }
static void update_toc(GooList* items, int level) { unsigned short ucs[256]; char label[256]; int i, j; if (! items) return; if (items->getLength() < 1) return; for (i = 0; i < items->getLength(); i++) { OutlineItem* outlineItem = (OutlineItem*)items->get(i); Unicode* title = outlineItem->getTitle(); int tlen = outlineItem->getTitleLength(); if (tlen > sizeof(ucs) - 1) tlen = sizeof(ucs) - 1; for (j = 0; j < tlen; j++) ucs[j] = (unsigned short)title[j]; ucs[j] = 0; ucs2utf(ucs, label, sizeof(label)); LinkAction* a = outlineItem->getAction(); if (a && (a->getKind() == actionGoTo)) { // page number is contained/referenced in a LinkGoTo LinkGoTo* g = static_cast< LinkGoTo* >(a); LinkDest* destination = g->getDest(); if (!destination && g->getNamedDest()) { GooString* s = g->getNamedDest(); if (named_size <= named_count + 1) { named_size += 64; named_dest = (char**) realloc(named_dest, named_size * sizeof(char*)); } named_dest[named_count] = strdup(s->getCString()); add_toc_item(level, label, -1, 100000 + named_count); named_count++; } else if (destination && destination->isOk() && destination->isPageRef()) { Ref page_ref = destination->getPageRef(); int num = doc->findPage(page_ref.num, page_ref.gen); add_toc_item(level, label, num, num); } else { add_toc_item(level, label, -1, -1); } } else { add_toc_item(level, label, -1, -1); } outlineItem->open(); GooList* children = outlineItem->getKids(); if (children) update_toc(children, level + 1); outlineItem->close(); } }
void NSRPopplerDocument::renderPage(int page) { double dpix, dpiy; if (_doc == NULL || page > getNumberOfPages() || page < 1) return; _page = _catalog->getPage(page); if (isTextOnly()) { PDFRectangle *rect; GooString *text; TextOutputDev *dev; dev = new TextOutputDev (0, gFalse, gFalse, gFalse); _doc->displayPageSlice(dev, _page->getNum(), 72, 72, 0, gFalse, gTrue, gFalse, -1, -1, -1, -1); rect = _page->getCropBox(); text = dev->getText(rect->x1, rect->y1, rect->x2, rect->y2); _text = processText(QString::fromUtf8(text->getCString())); delete text; delete dev; _readyForLoad = true; return; } if (isZoomToWidth()) { double wZoom = ((double) getScreenWidth() / (double) _page->getCropWidth() * 100.0); setZoomSilent((int) wZoom); } if (getZoom() > getMaxZoom()) setZoomSilent (getMaxZoom()); else if (getZoom() < getMinZoom()) setZoomSilent (getMinZoom()); if (_readyForLoad) _dev->startPage(0, NULL); dpix = _dpix * getZoom() / 100.0; dpiy = _dpiy * getZoom() / 100.0; _page->display(_dev, dpix, dpiy, getRotation(), gFalse, gFalse, gTrue, _catalog); _readyForLoad = true; }
GDir::GDir(char *name, GBool doStatA) { path = new GooString(name); doStat = doStatA; #if defined(WIN32) GooString *tmp; tmp = path->copy(); tmp->append("/*.*"); hnd = FindFirstFile(tmp->getCString(), &ffd); delete tmp; #elif defined(ACORN) #elif defined(MACOS) #else dir = opendir(name); #ifdef VMS needParent = strchr(name, '[') != NULL; #endif #endif }
void GDir::rewind() { #ifdef WIN32 GooString *tmp; if (hnd != INVALID_HANDLE_VALUE) FindClose(hnd); tmp = path->copy(); tmp->append("/*.*"); hnd = FindFirstFile(tmp->getCString(), &ffd); delete tmp; #elif defined(ACORN) #elif defined(MACOS) #else if (dir) rewinddir(dir); #ifdef VMS needParent = strchr(path->getCString(), '[') != NULL; #endif #endif }
static char * unicode_to_char (Unicode *unicode, int len) { static UnicodeMap *uMap = NULL; if (uMap == NULL) { GooString *enc = new GooString ("UTF-8"); uMap = globalParams->getUnicodeMap (enc); uMap->incRefCnt (); delete enc; } GooString gstr; char buf[8]; /* 8 is enough for mapping an unicode char to a string */ int i, n; for (i = 0; i < len; ++i) { n = uMap->mapUnicode (unicode[i], buf, sizeof (buf)); gstr.append (buf, n); } return strdup (gstr.getCString ()); }
GooString *appendToPath(GooString *path, char *fileName) { #if defined(VMS) //---------- VMS ---------- //~ this should handle everything necessary for file //~ requesters, but it's certainly not complete char *p0, *p1, *p2; char *q1; p0 = path->getCString(); p1 = p0 + path->getLength() - 1; if (!strcmp(fileName, "-")) { if (*p1 == ']') { for (p2 = p1; p2 > p0 && *p2 != '.' && *p2 != '['; --p2) ; if (*p2 == '[') ++p2; path->del(p2 - p0, p1 - p2); } else if (*p1 == ':') { path->append("[-]"); } else { path->clear(); path->append("[-]"); } } else if ((q1 = strrchr(fileName, '.')) && !strncmp(q1, ".DIR;", 5)) { if (*p1 == ']') { path->insert(p1 - p0, '.'); path->insert(p1 - p0 + 1, fileName, q1 - fileName); } else if (*p1 == ':') { path->append('['); path->append(']'); path->append(fileName, q1 - fileName); } else { path->clear(); path->append(fileName, q1 - fileName); } } else { if (*p1 != ']' && *p1 != ':') path->clear(); path->append(fileName); } return path; #elif defined(WIN32) //---------- Win32 ---------- GooString *tmp; char buf[256]; char *fp; tmp = new GooString(path); tmp->append('/'); tmp->append(fileName); GetFullPathName(tmp->getCString(), sizeof(buf), buf, &fp); delete tmp; path->clear(); path->append(buf); return path; #elif defined(ACORN) //---------- RISCOS ---------- char *p; int i; path->append("."); i = path->getLength(); path->append(fileName); for (p = path->getCString() + i; *p; ++p) { if (*p == '/') { *p = '.'; } else if (*p == '.') { *p = '/'; } } return path; #elif defined(MACOS) //---------- MacOS ---------- char *p; int i; path->append(":"); i = path->getLength(); path->append(fileName); for (p = path->getCString() + i; *p; ++p) { if (*p == '/') { *p = ':'; } else if (*p == '.') { *p = ':'; } } return path; #elif defined(__EMX__) //---------- OS/2+EMX ---------- int i; // appending "." does nothing if (!strcmp(fileName, ".")) return path; // appending ".." goes up one directory if (!strcmp(fileName, "..")) { for (i = path->getLength() - 2; i >= 0; --i) { if (path->getChar(i) == '/' || path->getChar(i) == '\\' || path->getChar(i) == ':') break; } if (i <= 0) { if (path->getChar(0) == '/' || path->getChar(0) == '\\') { path->del(1, path->getLength() - 1); } else if (path->getLength() >= 2 && path->getChar(1) == ':') { path->del(2, path->getLength() - 2); } else { path->clear(); path->append(".."); } } else { if (path->getChar(i-1) == ':') ++i; path->del(i, path->getLength() - i); } return path; } // otherwise, append "/" and new path component if (path->getLength() > 0 && path->getChar(path->getLength() - 1) != '/' && path->getChar(path->getLength() - 1) != '\\') path->append('/'); path->append(fileName); return path; #else //---------- Unix ---------- int i; // appending "." does nothing if (!strcmp(fileName, ".")) return path; // appending ".." goes up one directory if (!strcmp(fileName, "..")) { for (i = path->getLength() - 2; i >= 0; --i) { if (path->getChar(i) == '/') break; } if (i <= 0) { if (path->getChar(0) == '/') { path->del(1, path->getLength() - 1); } else { path->clear(); path->append(".."); } } else { path->del(i, path->getLength() - i); } return path; } // otherwise, append "/" and new path component if (path->getLength() > 0 && path->getChar(path->getLength() - 1) != '/') path->append('/'); path->append(fileName); return path; #endif }