示例#1
0
static void
display_chunks(ByteStream & out_str, IFFByteStream &iff,
	       const GUTF8String &head, DjVmInfo djvminfo)
{
  size_t size;
  GUTF8String id, fullid;
  GUTF8String head2 = head + "  ";
  GPMap<int,DjVmDir::File> djvmmap;
  int rawoffset;
  GMap<GUTF8String, int> counters;
  
  while ((size = iff.get_chunk(id, &rawoffset)))
  {
    if (!counters.contains(id)) counters[id]=0;
    else counters[id]++;
    
    GUTF8String msg;
    msg.format("%s%s [%d] ", (const char *)head, (const char *)id, size);
    out_str.format( "%s", (const char *)msg);
    // Display DJVM is when adequate
    if (djvminfo.dir)
    {
      GP<DjVmDir::File> rec = djvminfo.map[rawoffset];
      if (rec)
        {
          GUTF8String id = rec->get_load_name();
          GUTF8String title = rec->get_title();
          out_str.format( "{%s}", (const char*) id);
          if (rec->is_include())
            out_str.format(" [I]");
          if (rec->is_thumbnails())
            out_str.format(" [T]");
          if (rec->is_shared_anno())
            out_str.format(" [S]");
          if (rec->is_page())
            out_str.format(" [P%d]", rec->get_page_num()+1);
          if (id != title)
            out_str.format(" (%s)", (const char*)title);
        }
    }
    // Test chunk type
    iff.full_id(fullid);
    for (int i=0; disproutines[i].id; i++)
      if (fullid == disproutines[i].id || id == disproutines[i].id)
      {
        int n = msg.length();
        while (n++ < 14+(int) head.length()) putchar(out_str, ' ');
        if (!iff.composite()) out_str.format( "    ");
        (*disproutines[i].subr)(out_str, iff, head2,
                                size, djvminfo, counters[id]);
        break;
      }
      // Default display of composite chunk
      out_str.format( "\n");
      if (iff.composite())
        display_chunks(out_str, iff, head2, djvminfo);
      // Terminate
      iff.close_chunk();
  }
}
示例#2
0
// -- Helper for merge_and_split_ccs
static int
makeccid(const Grid_x_Color &x, GMap<Grid_x_Color,int> &map, int &ncc)
{
  GPosition p = map.contains(x);
  if (p) return map[p];
  return map[x] = ncc++;
}
示例#3
0
void
lt_XMLParser::Impl::parse_anno(
  const int width,
  const int height,
  const lt_XMLTags &GObject,
  GMap<GUTF8String,GP<lt_XMLTags> > &Maps,
  DjVuFile &dfile )
{
  GP<lt_XMLTags> map;
  {
    GPosition usemappos=GObject.get_args().contains("usemap");
    if(usemappos)
    {
      const GUTF8String mapname(GObject.get_args()[usemappos]);
      GPosition mappos=Maps.contains(mapname);
      if(!mappos)
      {
        G_THROW((ERR_MSG("XMLAnno.map_find") "\t")+mapname );
      }else
      {
        map=Maps[mappos];
      }
    }
  }
  if(map)
  {
    ChangeAnno(width,height,dfile,*map);
  }
}
示例#4
0
static const GMap<GUTF8String,GMapArea::BorderType> &
BorderTypeMap(void)
{
  static GMap<GUTF8String,GMapArea::BorderType> typeMap;
  if (! typeMap.size()) 
    {
      typeMap["none"]=GMapArea::NO_BORDER;
      typeMap["xor"]=GMapArea::XOR_BORDER;
      typeMap["solid"]=GMapArea::SOLID_BORDER;
      typeMap["default"]=GMapArea::SOLID_BORDER;
      typeMap["shadowout"]=GMapArea::SHADOW_OUT_BORDER;
      typeMap["shadowin"]=GMapArea::SHADOW_IN_BORDER;
      typeMap["etchedin"]=GMapArea::SHADOW_EIN_BORDER;
      typeMap["etchedout"]=GMapArea::SHADOW_EOUT_BORDER;
    }
  return typeMap;
}
示例#5
0
void
DjVuPortcaster::compute_closure(const DjVuPort * src, GPList<DjVuPort> &list, bool sorted)
{
   GCriticalSectionLock lock(&map_lock);
   GMap<const void*, void*> set;
   if (route_map.contains(src))
   {
      GList<void *> & list=*(GList<void *> *) route_map[src];
      for(GPosition pos=list;pos;++pos)
      {
	       DjVuPort * dst=(DjVuPort *) list[pos];
	       if (dst==src) add_to_closure(set, src, 0);
	       else add_to_closure(set, dst, 1);
      }
   }

   // Compute list
   GPosition pos;
   if (sorted)
     {
       // Sort in depth order
       int max_dist=0;
       for(pos=set;pos;++pos)
         if (max_dist < (int)(long)set[pos])
           max_dist = (int)(long)set[pos];
       GArray<GList<const void*> > lists(0,max_dist);
       for(pos=set;pos;++pos)
         lists[(int)(long)set[pos]].append(set.key(pos));
       for(int dist=0;dist<=max_dist;dist++)
         for(pos=lists[dist];pos;++pos)
           {
             GP<DjVuPort> p = is_port_alive((DjVuPort*) lists[dist][pos]);
             if (p) list.append(p);
           }
     }
   else
     {
       // Gather ports without order
       for(pos=set;pos;++pos)
         {
           GP<DjVuPort> p = is_port_alive((DjVuPort*) set.key(pos));
           if (p) list.append(p);
         }
     }
}
示例#6
0
static void
appendPath(const GURL &url, 
           GMap<GUTF8String,void *> &map,
           GList<GURL> &list)
{
  if( !url.is_empty() && !map.contains(url.get_string()) )
    {
      map[url.get_string()]=0;
      list.append(url);
    }
}
示例#7
0
void
DjVuPalette::allocate_hist()
{
  if (! hist)
    {
      hist = new GMap<int,int>;
      mask = 0;
    }
  else
    {
      GMap<int,int> *old = hist;
      hist = new GMap<int,int>;
      mask = (mask<<1)|(0x010101);
      for (GPosition p = *old; p; ++p)
        {
          int k = old->key(p);
          int w = (*old)[p];
          (*hist)[k | mask] += w;
        }
      delete old;
    }
}
GURL 
getExecDir(void)
{
  // This is the same as GetModulePath in DjVuMessage.cpp
 GURL retval;
 GUTF8String &xprogramname=DjVuMessage::programname();
 if(xprogramname.length())
 {
   if(xprogramname[1]=='/'
     ||!xprogramname.cmp("../",3)
     ||!xprogramname.cmp("./",2))
   {
     retval=GURL::Filename::UTF8(xprogramname);
   }
   if(retval.is_empty() || !retval.is_file())
   {
     GList<GURL> paths(parsePATH());
     GMap<GUTF8String,void *> pathMAP;
     for(GPosition pos=paths;pos;++pos)
     {
       retval=GURL::UTF8(xprogramname,paths[pos]);
       const GUTF8String path(retval.get_string());
       if(!pathMAP.contains(path))
       {
         if(retval.is_file())
           break;
         pathMAP[path]=0;
       }
     }
   }
   if (! retval.is_empty() )
     retval = retval.follow_symlinks();
   if (! retval.is_empty() )
     retval = retval.base();
 }
 return retval;
}
示例#9
0
void
DjVuPortcaster::add_to_closure(GMap<const void *, void *> & set,
			       const DjVuPort * dst, int distance)
{
  // Assuming that the map's already locked
  // GCriticalSectionLock lock(&map_lock);
  set[dst]= (void*) (unsigned long) distance;
  if (route_map.contains(dst))
    {
      GList<void *> & list=*(GList<void *> *) route_map[dst];
      for(GPosition pos=list;pos;++pos)
        {
          DjVuPort * new_dst=(DjVuPort *) list[pos];
          if (!set.contains(new_dst)) 
            add_to_closure(set, new_dst, distance+1);
        }
   }
}
示例#10
0
void GLogicProcessor::writeDictReportLocal(string &srcStr){
    
    int id=1;
    //int print=1;
    string str,dL,line;
    vector<dictKey> keyArray;
    ostringstream out;
    GMemory *longMemory=(GMemory*)inputData.longMemory;
    GMap *dict;
    GVector *dt;
    int translationMode=((GStr<int>*)inputData.pref)->get(22);
    GVector *dk;
    GMap *d;
    
    if(translationMode==TRANSLATE_ENG){
        str="translationDictEng";
    }else{
        str="translationDictRus";
    }
    longMemory->loadTable(str);
    dk=longMemory->table[str].data;
    indexRecord indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH);
    d=indexRec.mIndex;
    
    str="mainDict";
    longMemory->loadTable(str);
    indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH);
    dt=longMemory->table[str].data;
    GMap *dictKey=indexRec.mIndex;
    
    vector<uint>searchResult;
    //d->getKey(srcStr, searchResult,HASH_FIND);
    searchResult.push_back(d->getHKey(srcStr,0));
    for(int m=0;m<searchResult.size();m++) {
        TString st;
        dk->getTStr(searchResult[m], &st);
        str="="+st[1];
        out<<"["<<linkDict(st[0].c_str(),&id)<<linkEdit(str,&id)<<"]<hr>\n"<<endl;
    }
    
    searchResult.resize(0);
    //d->getKey(srcStr, searchResult,HASH_FIND);
    searchResult.push_back(d->getHKey(srcStr,0));
    for(int m=0;m<searchResult.size();m++) {
        TString st;
        dk->getTStr(searchResult[m], &st);
        str="="+st[1];
        str=str_replace(":|:YP", "", str);
        out<<"["<<linkDict(st[0].c_str(),&id)<<linkEdit(str,&id)<<"]<hr>\n"<<endl;
    }
    
    searchResult.resize(0);
    inputData.start=1;
    dict->getHKey(searchResult,srcStr,0);
    //dict->getKey(srcStr, searchResult,HASH_FIND);
    //cout<<"searchResult="<<searchResult.size()<<endl;
    vector<string>report;
    report.resize(25);
    
    for(int m=0;m<searchResult.size();m++) {
        TString st;
        dt->getTStr(searchResult[m], &st);
        str=st[2];
        line=st[1];
        if(str.find("[MG]")!=-1){
            report[0]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[HP]")!=-1){
            report[1]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[TD]")!=-1){
            report[2]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[MV]")!=-1){
            report[3]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[VD]")!=-1){
            report[4]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[EP]")!=-1){
            report[5]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[RE]")!=-1){
            report[6]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[SD]")!=-1){
            report[7]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[IW]")!=-1){
            report[8]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[JW]")!=-1){
            report[9]=line+"<br>\n"+st[2];
            continue;
        }
        
        if(str.find("[TT]")!=-1){
            lineTextTranslation(line);
            report[10]=line+"<br>\n"+st[2];
            continue;
        }
       if(str.find("[DK]")!=-1){
            lineTextTranslation(line);
            report[11]=line+"<br>\n"+st[2];
            continue;
        }
        if(str.find("[BB]")!=-1){
            continue;
        }
        if(str.find("[TS]")!=-1){
            continue;
        }
        if(str.find("[TR]")!=-1){
            continue;
        }
        string str=line+"<br>\n"+st[2];
        report.push_back(str);
        
    }
    for(int m=0;m<report.size();m++) {
        if(report[m].size())
            out<<srcStr<<"<br>\n"<<report[m]<<"<hr>\n"<<endl;
    }
    
    inputData.start=0;
    srcStr=out.str();
    //print(srcStr);
    
}//_____________________________________________________________________________
示例#11
0
static int set_two(const void *pKey, void *pValue, void *tmp)
{
    GMap *gm = (GMap *)tmp;
    gm->update(pKey, (void *)2);
    return 0;
}
示例#12
0
void GLogicProcessor::saveToTranslationDictionary(string &srcStr){
    vector<string>text=explode("[",srcStr);
    int index;
    string key,value;
    GMemory *longMemory=(GMemory*)inputData.longMemory;
    int translationMode=((GStr<int>*)inputData.pref)->get(22);
    GVector *dv;
    GMap *d;
    if(translationMode==TRANSLATE_ENG){
        dv=longMemory->translationDictEng;
        d=longMemory->translationDictGMapEng;
    }else{
        dv=longMemory->translationDictRus;
        d=longMemory->translationDictGMapRus;
    }
    //GMap *dictKey=longMemory->dictionaryGMap;
    
    for(int i=0;i<text.size();i++){
        string line=text[i];
        string reStr="<[^>]*>";
        std::regex key_regex(reStr);
        line = std::regex_replace(line, key_regex, "");
        reStr=".*=.*";
        std::regex key_regex_(reStr);
        line = std::regex_replace(line, key_regex_, "");
        if(line.size()<3)continue;
        index=(int)line.find("/");
        if(index<3)continue;
        index=(int)line.find("]");
        if(index<3)continue;
        line=substr(0, index, line);
        line=str_replace("/_", "/", line);
        vector<string>data=explode("/",line);
        if(data.size()<2)continue;
        key=data[0];
        value=data[1];
        key=key+"་";
        key=str_replace(" ","",key);
        key=str_replace("་་","་",key);
        value=str_replace("__","#",value);
        value=str_replace("_@","@",value);
        value=str_replace("#","__",value);
        value+="@";
        value=str_replace("@@","@",value);
        value=str_replace("{","༼",value);
        value=str_replace("«","༼",value);
        value=str_replace("}","༽",value);
        value=str_replace("»","༽",value);
        value=str_replace("༼༼","༼",value);
        value=str_replace("༽༽","༽",value);
        if(value.size()<3)continue;
        //cout<<"key="<<key<<" value="<<value<<endl;
        index=d->getHKey(key,0);
        //cout<<"index="<<index;
        TString st;
        if(value!="---"){
            st+=key;
            st+=value;
        }else{
            st+="";
            st+="";
        }
        if(index>-1){
            dv->putTStr(index, &st);
        }else{
            d->addRecord(&st);
        }
        
    }
    
}
示例#13
0
static GUTF8String
getbodies(
  GList<GURL> &paths,
  const GUTF8String &MessageFileName,
  GPList<lt_XMLTags> &body, 
  GMap<GUTF8String, void *> & map )
{
  GUTF8String errors;
  bool isdone=false;
  GPosition firstpathpos=paths;
  for(GPosition pathpos=firstpathpos;!isdone && pathpos;++pathpos)
  {
    const GURL::UTF8 url(MessageFileName,paths[pathpos]);
    if(url.is_file())
    {
      map[MessageFileName]=0;
      GP<lt_XMLTags> gtags;
      {
        GP<ByteStream> bs=ByteStream::create(url,"rb");
        G_TRY
        {
          gtags=lt_XMLTags::create(bs);
        }
        G_CATCH(ex)
        {
          GUTF8String mesg(failed_to_parse_XML+("\t"+url.get_string()));
          if(errors.length())
          {
            errors+="\n"+mesg;
          }else
          {
            errors=mesg;
          }
          errors+="\n"+GUTF8String(ex.get_cause());
        }
        G_ENDCATCH;
      }
      if(gtags)
      {
        lt_XMLTags &tags=*gtags;
        GPList<lt_XMLTags> Bodies=tags.get_Tags(bodystring);
        if(! Bodies.isempty())
        {
          isdone=true;
          for(GPosition pos=Bodies;pos;++pos)
          {
            body.append(Bodies[pos]);
          }
        }
        GPList<lt_XMLTags> Head=tags.get_Tags(headstring);
        if(! Head.isempty())
        {
          isdone=true;
          GMap<GUTF8String, GP<lt_XMLTags> > includes;
          lt_XMLTags::get_Maps(includestring,namestring,Head,includes);
          for(GPosition pos=includes;pos;++pos)
          {
            const GUTF8String file=includes.key(pos);
            if(! map.contains(file))
            {
              GList<GURL> xpaths;
              xpaths.append(url.base());
              const GUTF8String err2(getbodies(xpaths,file,body,map));
              if(err2.length())
              {
                if(errors.length())
                {
                  errors+="\n"+err2;
                }else
                {
                  errors=err2;
                }
              }
            }
          }
        }
      }
    }
  }
示例#14
0
GList<GURL>
DjVuMessage::GetProfilePaths(void)
{
  static bool first=true;
  static GList<GURL> realpaths;
  if(first)
  {
    first=false;
    GMap<GUTF8String,void *> pathsmap;
    GList<GURL> paths;
    GURL path;
    const GUTF8String envp(GOS::getenv(DjVuEnv));
    if(envp.length())
      appendPath(GURL::Filename::UTF8(envp),pathsmap,paths);
#if defined(WIN32) || defined(UNIX)
    GURL mpath(GetModulePath());
    if(!mpath.is_empty() && mpath.is_dir())
    {
#if defined(UNIX) && !defined(AUTOCONF) && !defined(NDEBUG)
      appendPath(GURL::UTF8(DebugModuleDjVuDir,mpath),pathsmap,paths);
#endif
      appendPath(mpath,pathsmap,paths);
      mpath=mpath.base();
      appendPath(GURL::UTF8(ModuleDjVuDir,mpath),pathsmap,paths);
      mpath=mpath.base();
      appendPath(GURL::UTF8(ModuleDjVuDir,mpath),pathsmap,paths);
    }
#endif
#if defined(AUTOCONF)
    GURL dpath = GURL::Filename::UTF8(DjVuDataDir);
    appendPath(dpath,pathsmap,paths);
#endif
#ifdef WIN32
    appendPath(RegOpenReadConfig(HKEY_CURRENT_USER),pathsmap,paths);
    appendPath(RegOpenReadConfig(HKEY_LOCAL_MACHINE),pathsmap,paths);
#else
    GUTF8String home=GOS::getenv("HOME");
# if HAVE_GETPWUID
    if (! home.length()) {
      struct passwd *pw=0;
      if ((pw = getpwuid(getuid())))
        home=GNativeString(pw->pw_dir);
    }
# endif
    if (home.length()) {
      GURL hpath = GURL::UTF8(LocalDjVuDir,GURL::Filename::UTF8(home));
      appendPath(hpath,pathsmap,paths);
    }
#endif
#ifdef LT_DEFAULT_PREFIX
    appendPath(GURL::Filename::UTF8(DjVuPrefixDir),pathsmap,paths);
#endif
    appendPath(GURL::Filename::UTF8(RootDjVuDir),pathsmap,paths);
    pathsmap.empty();

    GPosition pos;
    GList< GMap<GUTF8String,GP<lt_XMLTags> > > localemaps;
    for(pos=paths;pos;++pos)
    {
      path=GURL::UTF8(LanguageFile,paths[pos]);
      if(path.is_file())
      {
        const GP<lt_XMLTags> xml(lt_XMLTags::create(ByteStream::create(path,"rb")));
        const GPList<lt_XMLTags> Body(xml->get_Tags(bodystring));
        GPosition pos=Body;
        if(!pos || (pos != Body.lastpos()))
        {
          G_THROW( ERR_MSG("XMLAnno.extra_body") );
        }
        const GP<lt_XMLTags> GBody(Body[pos]);
        if(!GBody)
        {
          G_THROW( ERR_MSG("XMLAnno.no_body") );
        }
        GMap<GUTF8String,GP<lt_XMLTags> > localemap;
        lt_XMLTags::get_Maps(languagestring,localestring,Body,localemap);
        localemaps.append(localemap);
      }
    } 
    GList<GURL> localepaths;
    GList<GURL> osilocalepaths;

    // Need to do it the right way!
    GUTF8String defaultlocale = getenv("LANGUAGE");
    if (! defaultlocale) 
      {
        const GUTF8String oldlocale(setlocale(LC_MESSAGES,0));
        defaultlocale = setlocale(LC_MESSAGES,"");
        setlocale(LC_MESSAGES,(const char *)oldlocale);
      }
    // Unfathomable search.
    for(int loop=0; loop<2; loop++)
    {
      static const char sepchars[]=" _.@";
      const char *p=sepchars+sizeof(sepchars)-1;
      do
      {
        int sepcharpos=p[0]?defaultlocale.search(p[0]):defaultlocale.length();
        if(sepcharpos > 0)
        {
          const GUTF8String sublocale(defaultlocale,sepcharpos);
          const GUTF8String downcasesublocale("downcase^"+sublocale.downcase());
          for(pos=localemaps;pos;++pos) 
          {
            const GMap<GUTF8String,GP<lt_XMLTags> > &localemap=localemaps[pos];
            GPosition pos=localemap.contains(sublocale);
            if(!pos)
              pos=localemap.contains(downcasesublocale);
            if(pos)
            {
              const GMap<GUTF8String,GUTF8String>&args
                = localemap[pos]->get_args();
              pos = args.contains(srcstring);
              if (pos)
              {
                const GUTF8String src(args[pos]);
                for(pos=paths;pos;++pos)
                {
                  path=GURL::UTF8(src,paths[pos]);
                  if(path.is_dir())
                    localepaths.append(path);
                  path=GURL::UTF8(GUTF8String(opensourcedir)+"/"+src,paths[pos]);
                  if(path.is_dir())
                    osilocalepaths.append(path);
                }
              }
              // We don't need to check anymore language files.
              p=sepchars;
              break;
            }
          }
          if(!pos)
          {
            for(pos=paths;pos;++pos)
            {
              path=GURL::UTF8(sublocale,paths[pos]);
              if(path.is_dir())
              {
                localepaths.append(path);
              }
              path=GURL::UTF8(GUTF8String(opensourcedir)+"/"+sublocale,paths[pos]);
              if(path.is_dir())
              {
                osilocalepaths.append(path);
              }
            }
          }
        }
      } while(p-- != sepchars);
      if((GPosition) localepaths)
        break;
      defaultlocale="C";
    }
    for(pos=localepaths;pos;++pos)
      appendPath(localepaths[pos],pathsmap,realpaths);
    for(pos=paths;pos;++pos)
      appendPath(paths[pos],pathsmap,realpaths);
    for(pos=osilocalepaths;pos;++pos)
      appendPath(osilocalepaths[pos],pathsmap,realpaths);
    for(pos=paths;pos;++pos)
      {
        path=GURL::UTF8(opensourcedir,paths[pos]);
        appendPath(path,pathsmap,realpaths);
      }
  }
  return realpaths;
}
示例#15
0
/** @brief translate text lines and write result in destString*/
void GLogicProcessor::lineTextTranslation(string &destString){
    
    GMemory *longMemory=(GMemory*)inputData.longMemory;
    int translationMode=((GStr<int>*)inputData.pref)->get(22);
    string ln=inputData.data["ln"];
    if(ln!=""){
        if(ln=="rus")translationMode=TRANSLATE_RUS;
        if(ln=="eng")translationMode=TRANSLATE_ENG;
    }
    GVector *dk;
    GMap *d;
    string str;
    if(translationMode==TRANSLATE_ENG){
        str="translationDictEng";
    }else{
        str="translationDictRus";
    }
    longMemory->loadTable(str);
    dk=longMemory->table[str].data;
    indexRecord indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH);
    d=indexRec.mIndex;
    
    str="mainDict";
    longMemory->loadTable(str);
    indexRec=longMemory->createIndex(longMemory->table[str], 0, HASH_SEARCH);
    GMap *dictKey=indexRec.mIndex;
    
    
    string src,line,ld,l1,c,c1,c2,report,res,resD;
    int i,j,start,end,lng,index;
    int mode=inputData.mode;
    
    destString=str_replace("། ","།\n",destString);
    destString=str_replace("།་","།\n",destString);
    destString=str_replace("༎","།\n",destString);
    destString=str_replace("༔ ","༔\n",destString);
    destString=str_replace("༴ ","༴\n",destString);
    destString=str_replace("ག ","ག\n",destString);
    
    vector<string>text=explode("\n",destString);
    
    int id=1;
    //text.resize(1); text[0]="གང་ཟག་ཏུ་ལྟ་(༦)བའམ།";
    //line="རྣམས་";
    //TString st;
    //dk->getTStr(109073, &st);
    //cout<<"st="<<st.size()<<" st[0]="<<st[0]<<endl;
    //exit(0);
    //index=d->getHKey(line);
    //cout<<"index="<<index<<endl;
    //exit(0);
    //cout<<"text.size()="<<text.size()<<endl;
    
    //dictKey->hashError=0;
    //dictKey->maxHashError=0;
    //dictKey->hashCount=0;
    
    report="";
    int step=0;
    
    for(int lineIndex=0;lineIndex<text.size();lineIndex++){
        if(step==1000){
            print(lineIndex<<" from "<<text.size());
            step=0;
        }
        step++;
        str=text[lineIndex];
        //cout<<"str="<<str<<endl;
        src=str;
        lng=(int)str.size();
        if(lng<2)continue;
        if(str.find("་")==-1){
            report+=src+"\n<br>";
            continue;
        }
        str=clearText(str);
        //str=str_replace("[ _\d\ "	\"\*\(\)\{\}\[\]@//\%\&༄༅༔༴༡༢༣༤༥༦༧༨༩༠༎།༑༈༌༐༼༽ऀ-ॿ]","་",str)
        str=str_replace("ཿ","་ཿ་",str);
        str=str_replace("│","",str);
        str=str+"་།";
        str=str_replace("་་","་",str);
        //str=str_replace("([^་])འོ་།","\1་(точка)་",str);
        //str=str_replace("([^་])འམ་།","\1་[འམ=или]་",str);
        str=str_replace("ག་གོ་།","ག་(¶)་",str);
        str=str_replace("ང་ངོ་།","ང་(¶)་",str);
        str=str_replace("ད་དོ་།","ད་(¶)་",str);
        str=str_replace("ན་ནོ་།","ན་(¶)་",str);
        str=str_replace("བ་བོ་།","བ་(¶)་",str);
        str=str_replace("མ་མོ་།","མ་(¶)་",str);
        str=str_replace("ར་རོ་།","ར་(¶)་",str);
        str=str_replace("ལ་ལོ་།","ལ་(¶)་",str);
        str=str_replace("ས་སོ་།","ས་(¶)་",str);
        str=str_replace("་ཏོ་།","་(¶)་",str);
        //str=str_replace("་པའང་","་པ་[འང=уступ.]་",str);
        //str=str_replace("་བའང་","་བ་[འང=уступ.]་",str);
        
        vector<string>l=explode("་",str);
        res="";
        resD="";
        
        lng=(int)l.size();
        start=0;
        end=lng-1;
        
        i=lng;
        
        while(start<lng){
            //make query string decrease end
            end=lng;
            while(end>-1){
                j=start;
                line="";
                //increase start
                while (j < end){
                    line+=l[j]+"་";
                    j++;
                }
                //count+=1
                //cout<<line<<" "<<start<<" "<<end<<endl;
                //if (count >120):
                //return
                index=d->getHKey(line,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(line,&id)+linkEdit(c,&id)+"]་";
                    if(c.find("__")!=-1){
                        end-=1;
                        res+="<br>\n";
                        continue;
                    }
                    if(mode==FULL_REPORT && start==0 && end==lng-1){
                        end-=1;
                        continue;
                    }
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(line,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(line,&id)+linkEdit("=",&id)+"] ";
                }
                ln=line+"@";
                
                l1=str_replace("འི་@","་",ln);
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འི་",&id)+linkEdit("=g.p",&id)+"]་";
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(l1,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] ";
                }
                
                l1=str_replace("ས་@","་",ln);
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-ས་",&id)+linkEdit("=i.p.",&id)+"]་";
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(l1,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] ";
                }
                
                l1=str_replace("ར་@","་",ln);
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-ར་",&id)+linkDict("=d.l.",&id)+"]་";
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(l1,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] ";
                }
                
                l1=str_replace("འོ་@","་",ln);
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འོ་",&id)+linkEdit("=(точка)",&id)+"]་";
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(l1,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(line,&id)+linkEdit("=",&id)+"] ";
                }
                
                l1=str_replace("འམ་@","་",ln);
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་["+linkDict("-འམ་",&id)+linkEdit("=или",&id)+"]་";
                    start=end-1;
                    break;
                }
                //next check big dictionary report
                index=dictKey->getHKey(l1,0);
                if(line.size()>3 && index!=-1){
                    resD+="["+linkDict(l1,&id)+linkEdit("=",&id)+"] ";
                }
                end-=1;
                if(end==start){
                    res+=line;
                    break;
                }
            }
            start++;
        }
        res=str_replace(":|:YP","",res);
        report+=linkOriginal(src,&id)+"<br>\n@<c>"+res+"</c>\n";
        if(resD.size()>10){
            report+="@";
            report+=resD+"<br>\n";
        }else{
            report+="<br>\n";
        }
        
        if(mode==FULL_REPORT){
            res="";
            for (int t=0;t<l.size();t++){
                line=l[t];
                l1=line+"་";
                index=d->getHKey(l1,0);
                if(index!=-1){
                    TString st;
                    dk->getTStr(index, &st);
                    c="="+st[1];
                    res+="["+linkDict(l1,&id)+linkEdit(c,&id)+"]་";
                }
            }
            res=str_replace(":|:YP","",res);
            report+="<c>"+res+"</c>\n<br>\n";
        }
        //break;
        
    }
    report=str_replace("<br>\n<br>", "<br>\n",report);
    //print("@@@@"<<report);
    destString=report;
    
    //cout<<"    dictKey->hashError="<<dictKey->hashError<<" dictKey->maxHashError="<<dictKey->maxHashError<<" dictKey->hashCount="<<dictKey->hashCount<<endl;
    //cout<<"maxHashSize="<<(0xffffffff>>7)<<endl;
    //exit(0);
    
}
示例#16
0
void
lt_XMLParser::Impl::parse(const lt_XMLTags &tags, GURL *pdjvufile)
{
  const GPList<lt_XMLTags> Body(tags.get_Tags(bodytag));
  GPosition pos=Body;
 
  if(!pos || (pos != Body.lastpos()))
  {
    G_THROW( ERR_MSG("XMLAnno.extra_body") );
  }
  const GP<lt_XMLTags> GBody(Body[pos]);
  if(!GBody)
  {
    G_THROW( ERR_MSG("XMLAnno.no_body") );
  }

  GMap<GUTF8String,GP<lt_XMLTags> > Maps;
  lt_XMLTags::get_Maps(maptag,"name",Body,Maps);

  const GPList<lt_XMLTags> Objects(GBody->get_Tags(objecttag));
  lt_XMLTags::get_Maps(maptag,"name",Objects,Maps);

  for(GPosition Objpos=Objects;Objpos;++Objpos)
  {
    lt_XMLTags &GObject=*Objects[Objpos];
    // Map of attributes to value (e.g. "width" --> "500")
    const GMap<GUTF8String,GUTF8String> &args=GObject.get_args();
    GURL codebase;
    {
      DEBUG_MSG("Setting up codebase... m_codebase = " << m_codebase << "\n");
      GPosition codebasePos=args.contains("codebase");
      // If user specified a codebase attribute, assume it is correct (absolute URL):
      //  the GURL constructor will throw an exception if it isn't
      if(codebasePos)
      {
        codebase=GURL::UTF8(args[codebasePos]);
      }else if (m_codebase.is_dir())
      {
        codebase=m_codebase;
      }else
      {
        codebase=GURL::Filename::UTF8(GOS::cwd());
      }
      DEBUG_MSG("codebase = " << codebase << "\n");
    }
    // the data attribute specifies the input file.  This can be
    //  either an absolute URL (starts with file:/) or a relative
    //  URL (for now, just a path and file name).  If it's absolute,
    //  our GURL will adequately wrap it.  If it's relative, we need
    //  to use the codebase attribute to form an absolute URL first.
    GPosition datapos=args.contains("data");
    if(datapos)
    {
      bool isDjVuType=false;
      GPosition typePos(args.contains("type"));
      if(typePos)
      {
        if(args[typePos] != mimetype)
        {
          // DjVuPrintErrorUTF8("Ignoring %s Object tag\n",mimetype);
          continue;
        }
        isDjVuType=true;
      }
      const GURL url = (pdjvufile) ? *pdjvufile 
        : GURL::UTF8(args[datapos], 
                     (args[datapos][0] == '/') ? codebase.base() : codebase);
      int width;
      {
        GPosition widthPos=args.contains("width");
        width=(widthPos)?args[widthPos].toInt():0;
      }
      int height;
      {
        GPosition heightPos=args.contains("height");
        height=(heightPos)?args[heightPos].toInt():0;
      }
      GUTF8String gamma;
      GUTF8String dpi;
      GUTF8String page;
      GUTF8String do_ocr;
      {
        GPosition paramPos(GObject.contains(paramtag));
        if(paramPos)
        {
          const GPList<lt_XMLTags> Params(GObject[paramPos]);
          for(GPosition loc=Params;loc;++loc)
          {
            const GMap<GUTF8String,GUTF8String> &pargs=Params[loc]->get_args();
            GPosition namepos=pargs.contains("name");
            if(namepos)
            {
              GPosition valuepos=pargs.contains("value");
              if(valuepos)
              {
                const GUTF8String name=pargs[namepos].downcase();
                const GUTF8String &value=pargs[valuepos];
                if(name == "flags")
                {
                  GMap<GUTF8String,GUTF8String> args;
                  lt_XMLTags::ParseValues(value,args,true);
                  if(args.contains("page"))
                  {
                    page=args["page"];
                  }
                  if(args.contains("dpi"))
                  {
                    dpi=args["dpi"];
                  }
                  if(args.contains("gamma"))
                  {
                    gamma=args["gamma"];
                  }
                  if(args.contains("ocr"))
                  {
                    do_ocr=args["ocr"];
                  }
                }else if(name == "page")
                {
                  page=value;
                }else if(name == "dpi")
                {
                  dpi=value;
                }else if(name == "gamma")
                {
                  gamma=value;
                }else if(name == "ocr")
                {
                  do_ocr=value;
                }
              }
            }
          }
        }
      }
      const GP<DjVuFile> dfile(get_file(url,page));
      if(dpi.is_int() || gamma.is_float())
      {
        int pos=0;
        ChangeInfo(*dfile,dpi.toInt(),gamma.toDouble(pos,pos));
      }
      parse_anno(width,height,GObject,Maps,*dfile);
      parse_meta(GObject,*dfile);
      parse_text(width,height,GObject,*dfile);
      ChangeTextOCR(do_ocr,width,height,dfile);
    }
  }
}
示例#17
0
void
lt_XMLParser::Impl::ChangeAnno(
  const int width, const int height,
  DjVuFile &dfile, 
  const lt_XMLTags &map )
{
  dfile.resume_decode(true);
  const GP<DjVuInfo> info(dfile.info);
  const GP<DjVuAnno> ganno(DjVuAnno::create());
  DjVuAnno &anno=*ganno;
  GPosition map_pos;
  map_pos=map.contains(areatag);
  if(dfile.contains_anno())
  {
    GP<ByteStream> annobs=dfile.get_merged_anno();
    if(annobs)
    {
      anno.decode(annobs);
      if(anno.ant && info)
      {
        anno.ant->map_areas.empty();
      }
    }
//    dfile.remove_anno();
  }
  if(info && map_pos)
  {
    const int h=info->height;
    const int w=info->width;
    double ws=1.0;
    double hs=1.0;
    if(width && width != w)
    {
      ws=((double)w)/((double)width); 
    }
    if(height && height != h)
    {
      hs=((double)h)/((double)height); 
    }
    if(!anno.ant)
    {
      anno.ant=DjVuANT::create();
    }
    GPList<GMapArea> &map_areas=anno.ant->map_areas;
    map_areas.empty();
    GPList<lt_XMLTags> gareas=map[map_pos];
    for(GPosition pos=gareas;pos;++pos)
    {
      if(gareas[pos])
      {
        lt_XMLTags &areas=*(gareas[pos]);
        GMap<GUTF8String,GUTF8String> args(areas.get_args());
        GList<int> coords;
        // ******************************************************
        // Parse the coords attribute:  first read the raw data into
        // a list, then scale the x, y data into another list.  For
        // circles, you also get a radius element with (looks like an x
        // with no matching y).
        // ******************************************************
        {
          GPosition coords_pos=args.contains("coords");
          if(coords_pos)
          {
            GList<int> raw_coords;
            intList(args[coords_pos],raw_coords);
            for(GPosition raw_pos=raw_coords;raw_pos;++raw_pos)
            {
              const int r=raw_coords[raw_pos];
              const int x=(int)(ws*(double)r+0.5);
              coords.append(x);
              int y=h-1;
              if(! ++raw_pos)
              {
                y-=(int)(hs*(double)r+0.5);
              }else
              {
                y-=(int)(hs*(double)raw_coords[raw_pos]+0.5);
              }
              coords.append(y);
//            DjVuPrintMessage("Coords (%d,%d)\n",x,y);
            }
          }
        }
        GUTF8String shape;
        {
          GPosition shape_pos=args.contains("shape");
          if(shape_pos)
          {
            shape=args[shape_pos];
          }
        }
        GP<GMapArea> a;
        if(shape == "default")
        {
          GRect rect(0,0,w,h);
          a=GMapRect::create(rect);
        }else if(!shape.length() || shape == "rect")
        {
          int xx[4];
          int i=0;
          for(GPosition rect_pos=coords;(rect_pos)&&(i<4);++rect_pos,++i)
          {
            xx[i]=coords[rect_pos];
          }
          if(i!=4)
          {
            G_THROW( ERR_MSG("XMLAnno.bad_rect") );
          }
          int xmin,xmax; 
          if(xx[0]>xx[2])
          {
            xmax=xx[0];
            xmin=xx[2];
          }else
          {
            xmin=xx[0];
            xmax=xx[2];
          }
          int ymin,ymax; 
          if(xx[1]>xx[3])
          {
            ymax=xx[1];
            ymin=xx[3];
          }else
          {
            ymin=xx[1];
            ymax=xx[3];
          }
          GRect rect(xmin,ymin,xmax-xmin,ymax-ymin);
          a=GMapRect::create(rect);
        }else if(shape == "circle")
        {
          int xx[4];
          int i=0;
          GPosition rect_pos=coords.lastpos();
          if(rect_pos)
          {
            coords.append(coords[rect_pos]);
            for(rect_pos=coords;(rect_pos)&&(i<4);++rect_pos)
            {
              xx[i++]=coords[rect_pos];
            }
          }
          if(i!=4)
          {
            G_THROW( ERR_MSG("XMLAnno.bad_circle") );
          }
          int x=xx[0],y=xx[1],rx=xx[2],ry=(h-xx[3])-1;
          GRect rect(x-rx,y-ry,2*rx,2*ry);
          a=GMapOval::create(rect);
        }else if(shape == "oval")
        {
          int xx[4];
          int i=0;
          for(GPosition rect_pos=coords;(rect_pos)&&(i<4);++rect_pos,++i)
          {
            xx[i]=coords[rect_pos];
          }
          if(i!=4)
          {
            G_THROW( ERR_MSG("XMLAnno.bad_oval") );
          }
          int xmin,xmax; 
          if(xx[0]>xx[2])
          {
            xmax=xx[0];
            xmin=xx[2];
          }else
          {
            xmin=xx[0];
            xmax=xx[2];
          }
          int ymin,ymax; 
          if(xx[1]>xx[3])
          {
            ymax=xx[1];
            ymin=xx[3];
          }else
          {
            ymin=xx[1];
            ymax=xx[3];
          }
          GRect rect(xmin,ymin,xmax-xmin,ymax-ymin);
          a=GMapOval::create(rect);
        }else if(shape == "poly")
        {
          GP<GMapPoly> p=GMapPoly::create();
          for(GPosition poly_pos=coords;poly_pos;++poly_pos)
          {
            int x=coords[poly_pos];
            if(! ++poly_pos)
              break;
            int y=coords[poly_pos];
            p->add_vertex(x,y);
          }
          p->close_poly();
          a=p;
        }else
        {
          G_THROW( ( ERR_MSG("XMLAnno.unknown_shape") "\t")+shape );
        }
        if(a)
        {
          GPosition pos;
          if((pos=args.contains("href")))
          {
            a->url=args[pos];
          }
          if((pos=args.contains("target")))
          {
            a->target=args[pos];
          }
          if((pos=args.contains("alt")))
          {
            a->comment=args[pos];
          }
          if((pos=args.contains("bordertype")))
          {
            GUTF8String b=args[pos];
            static const GMap<GUTF8String,GMapArea::BorderType> typeMap=BorderTypeMap();
            if((pos=typeMap.contains(b)))
            {
              a->border_type=typeMap[pos];
            }else
            {
              G_THROW( (ERR_MSG("XMLAnno.unknown_border") "\t")+b );
            }
          }
          a->border_always_visible=!!args.contains("visible");
          if((pos=args.contains("bordercolor")))
          {
            a->border_color=convertToColor(args[pos]);
          }
          if((pos=args.contains("highlight")))
          {
            a->hilite_color=convertToColor(args[pos]);
          }
          if((pos=args.contains("border")))
          {
             a->border_width=args[pos].toInt(); //atoi(args[pos]);
          }
          map_areas.append(a);
        }
      }
    }
  }
  dfile.set_modified(true);
  dfile.anno=ByteStream::create();
  anno.encode(dfile.anno);
}