Exemplo n.º 1
0
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();
	}
}
Exemplo n.º 2
0
KPDFLink * KPDFOutputDev::generateLink( LinkAction * a )
// note: this function is called when processing a page, when the MUTEX is already LOCKED
{
    KPDFLink * link = NULL;
    if ( a ) switch ( a->getKind() )
    {
        case actionGoTo:
            {
            LinkGoTo * g = (LinkGoTo *) a;
            // ceate link: no ext file, namedDest, object pointer
            link = new KPDFLinkGoto( QString::null, decodeViewport( g->getNamedDest(), g->getDest() ) );
            }
            break;

        case actionGoToR:
            {
            LinkGoToR * g = (LinkGoToR *) a;
            // copy link file
            const char * fileName = g->getFileName()->getCString();
            // ceate link: fileName, namedDest, object pointer
            link = new KPDFLinkGoto( (QString)fileName, decodeViewport( g->getNamedDest(), g->getDest() ) );
            }
            break;

        case actionLaunch:
            {
            LinkLaunch * e = (LinkLaunch *)a;
            GString * p = e->getParams();
            link = new KPDFLinkExecute( e->getFileName()->getCString(), p ? p->getCString() : 0 );
            }
            break;

        case actionNamed:
            {
            const char * name = ((LinkNamed *)a)->getName()->getCString();
            if ( !strcmp( name, "NextPage" ) )
                link = new KPDFLinkAction( KPDFLinkAction::PageNext );
            else if ( !strcmp( name, "PrevPage" ) )
                link = new KPDFLinkAction( KPDFLinkAction::PagePrev );
            else if ( !strcmp( name, "FirstPage" ) )
                link = new KPDFLinkAction( KPDFLinkAction::PageFirst );
            else if ( !strcmp( name, "LastPage" ) )
                link = new KPDFLinkAction( KPDFLinkAction::PageLast );
            else if ( !strcmp( name, "GoBack" ) )
                link = new KPDFLinkAction( KPDFLinkAction::HistoryBack );
            else if ( !strcmp( name, "GoForward" ) )
                link = new KPDFLinkAction( KPDFLinkAction::HistoryForward );
            else if ( !strcmp( name, "Quit" ) )
                link = new KPDFLinkAction( KPDFLinkAction::Quit );
            else if ( !strcmp( name, "GoToPage" ) )
                link = new KPDFLinkAction( KPDFLinkAction::GoToPage );
            else if ( !strcmp( name, "Find" ) )
                link = new KPDFLinkAction( KPDFLinkAction::Find );
            else if ( !strcmp( name, "Close" ) )
                link = new KPDFLinkAction( KPDFLinkAction::Close );
            else
                kdDebug() << "Unknown named action: '" << name << "'" << endl;
            }
            break;

        case actionURI:
            link = new KPDFLinkBrowse( ((LinkURI *)a)->getURI()->getCString() );
            break;

        case actionMovie:
/*          { TODO this (Movie link)
            m_type = Movie;
            LinkMovie * m = (LinkMovie *) a;
            // copy Movie parameters (2 IDs and a const char *)
            Ref * r = m->getAnnotRef();
            m_refNum = r->num;
            m_refGen = r->gen;
            copyString( m_uri, m->getTitle()->getCString() );
            }
*/          break;

        case actionUnknown:
            kdDebug() << "Unknown link." << endl;
            break;
    }

    // link may be zero at that point
    return link;
}