Ejemplo n.º 1
0
GP<DjVuFile>
lt_XMLParser::Impl::get_file(const GURL &url,GUTF8String id)
{
  GP<DjVuFile> dfile;
  GP<DjVuDocument> doc;
  GCriticalSectionLock lock(&xmlparser_lock);
  {
    GPosition pos=m_docs.contains(url.get_string());
    if(pos)
    {
      doc=m_docs[pos];
    }else
    {
      doc=DjVuDocument::create_wait(url);
      if(! doc->wait_for_complete_init())
      {
        G_THROW(( ERR_MSG("XMLAnno.fail_init") "\t")+url.get_string() );
      }
      m_docs[url.get_string()]=doc;
    }
    if(id.is_int())
    {
      const int xpage=id.toInt(); //atoi((char const *)page); 
      if(xpage>0)
        id=doc->page_to_id(xpage-1);
    }else if(!id.length())
    { 
      id=doc->page_to_id(0);
    }
  }
  const GURL fileurl(doc->id_to_url(id));
  GPosition dpos(m_files.contains(fileurl.get_string()));
  if(!dpos)
  {
    if(!doc->get_id_list().contains(id))
    {
      G_THROW( ERR_MSG("XMLAnno.bad_page") );
    }
    dfile=doc->get_djvu_file(id,false);
    if(!dfile)
    {
      G_THROW( ERR_MSG("XMLAnno.bad_page") );
    }
    m_files[fileurl.get_string()]=dfile;
  }else
  {
    dfile=m_files[dpos];
  }
  return dfile;
}
Ejemplo n.º 2
0
void PageInfo::Update(GP<DjVuImage> pImage)
{
	if (pImage == NULL)
		return;

	if (!bDecoded)
	{
		nInitialRotate = GetTotalRotate(pImage, 0);

		szPage = CSize(pImage->get_width(), pImage->get_height());
		if (nInitialRotate % 2 != 0)
			swap(szPage.cx, szPage.cy);

		nDPI = pImage->get_dpi();
		if (szPage.cx <= 0 || szPage.cy <= 0)
		{
			szPage.cx = 100;
			szPage.cy = 100;
			nDPI = 100;
		}

		bHasText = !!(pImage->get_djvu_file()->text != NULL);
		bDecoded = true;
	}

	try
	{
		if (bHasText && !bTextDecoded)
			DecodeText(pImage->get_text());
	}
	catch (GException&)
	{
	}

	try
	{
		if (!bAnnoDecoded)
			DecodeAnno(pImage->get_anno());
	}
	catch (GException&)
	{
	}
}