patch-libdjvu_DjVmDir_cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. $OpenBSD: patch-libdjvu_DjVmDir_cpp,v 1.1 2016/03/02 20:10:36 juanfra Exp $
  2. "accept documents with duplicate page titles"
  3. http://sourceforge.net/p/djvu/djvulibre-git/ci/77a4dca8dd3acd0acc1680fa14a352c11084e25d/
  4. https://bitbucket.org/jwilk/pdf2djvu/issues/113/duplicate-page-title-1
  5. --- libdjvu/DjVmDir.cpp.orig Tue Jul 8 23:15:07 2014
  6. +++ libdjvu/DjVmDir.cpp Wed Feb 3 01:51:28 2016
  7. @@ -223,7 +223,6 @@ DjVmDir::decode(const GP<ByteStream> &gstr)
  8. page2file.resize(-1);
  9. name2file.empty();
  10. id2file.empty();
  11. - title2file.empty();
  12. int ver=str.read8();
  13. bool bundled=(ver & 0x80)!=0;
  14. @@ -375,18 +374,6 @@ DjVmDir::decode(const GP<ByteStream> &gstr)
  15. G_THROW( ERR_MSG("DjVmDir.dupl_id") "\t" + file->id);
  16. id2file[file->id]=file;
  17. }
  18. -
  19. - // Generate title2file map
  20. - for(pos=files_list;pos;++pos)
  21. - {
  22. - GP<File> file=files_list[pos];
  23. - if (file->title.length())
  24. - {
  25. - if (title2file.contains(file->title))
  26. - G_THROW( ERR_MSG("DjVmDir.dupl_title") "\t" + file->title);
  27. - title2file[file->title]=file;
  28. - }
  29. - }
  30. }
  31. }
  32. @@ -556,11 +543,19 @@ DjVmDir::id_to_file(const GUTF8String &id) const
  33. }
  34. GP<DjVmDir::File>
  35. -DjVmDir::title_to_file(const GUTF8String &title) const
  36. +DjVmDir::title_to_file(const GUTF8String &title, GPosition spos) const
  37. {
  38. - GCriticalSectionLock lock((GCriticalSection *) &class_lock);
  39. - GPosition pos;
  40. - return (title2file.contains(title, pos))?title2file[pos]:(GP<DjVmDir::File>(0));
  41. + if (! title)
  42. + return 0;
  43. + GCriticalSectionLock lock((GCriticalSection *) &class_lock);
  44. + if (! spos)
  45. + for (GPosition pos = spos; pos; ++pos)
  46. + if (files_list[pos]->is_page() && files_list[pos]->title == title)
  47. + return files_list[pos];
  48. + for (GPosition pos = files_list; pos; ++pos)
  49. + if (files_list[pos]->is_page() && files_list[pos]->title == title)
  50. + return files_list[pos];
  51. + return 0;
  52. }
  53. GP<DjVmDir::File>
  54. @@ -661,14 +656,7 @@ DjVmDir::insert_file(const GP<File> & file, int pos_nu
  55. G_THROW( ERR_MSG("DjVmDir.dupl_name2") "\t" + file->name);
  56. name2file[file->name]=file;
  57. id2file[file->id]=file;
  58. - if (file->title.length())
  59. - {
  60. - if (title2file.contains(file->title))
  61. - // duplicate titles may become ok some day
  62. - G_THROW( ERR_MSG("DjVmDir.dupl_title2") "\t" + file->title);
  63. - title2file[file->title]=file;
  64. - }
  65. -
  66. +
  67. // Make sure that there is no more than one file with shared annotations
  68. if (file->is_shared_anno())
  69. {
  70. @@ -727,7 +715,6 @@ DjVmDir::delete_file(const GUTF8String &id)
  71. {
  72. name2file.del(f->name);
  73. id2file.del(f->id);
  74. - title2file.del(f->title);
  75. if (f->is_page())
  76. {
  77. for(int page=0;page<page2file.size();page++)
  78. @@ -788,9 +775,7 @@ DjVmDir::set_file_title(const GUTF8String &id, const G
  79. if (!id2file.contains(id, pos))
  80. G_THROW( ERR_MSG("DjVmDir.no_info") "\t" + GUTF8String(id));
  81. GP<File> file=id2file[pos];
  82. - title2file.del(file->title);
  83. file->title=title;
  84. - title2file[title]=file;
  85. }
  86. GPList<DjVmDir::File>