Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 djvulibre (3.5.25.4-1) unstable; urgency=low
 .
   * new upstream release
   * merge upstream changes for crash report, see
     http://lists.debian.org/debian-devel/2013/06/msg00720.html
     http://www.forallsecure.com/bug-reports/df37d30856756929f929ec8e508af1a574109c0d/
   * flush dh-exec overkill
   * enable full multiarch support
   * bump standard version
   * canonicalize development repo urls
Author: Barak A. Pearlmutter <bap@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- djvulibre-3.5.25.4.orig/NEWS
+++ djvulibre-3.5.25.4/NEWS
@@ -1,6 +1,15 @@
+NEW SINCE VERSION 3.5.25
+------------------------
+- New windows installer. 
+- Fixed Russian code page issues in windows
+- General speedup thanks to lock-free smart pointers
+- ddjvu can produce one file per page
+- djvused can now set the default page orientation
+- Big fixes.
+
 
 NEW IN VERSION 3.5.25
-------------------------
+---------------------
 - Removed the deprecated djview3 code.
 - Removed the deprecated cothreads code.
 - Removed the unmaintained japanese man pages.
--- djvulibre-3.5.25.4.orig/tools/djvused.1
+++ djvulibre-3.5.25.4/tools/djvused.1
@@ -542,7 +542,23 @@ Display the width and the height of the
 dimensions of each page are displayed using a syntax suitable for
 direct insertion into the
 .SM <EMBED...></EMBED>
-tags.
+tags. This command also displays the default page orientation
+when it is different from zero.
+.TP
+.BI "set-rotation [+-]" "rot"
+Changes the default orientation of the selected pages.
+The orientation is expressed as an integer in range 0..3
+representing a number of 90 degree counter-clockwise rotations.
+When the argument is preceded by a sign
+.BR "+" " or " "-" ","
+argument
+.I rot
+counts how many additional 90 degree counter-clockwise rotations
+should be applied to the page. Otherwise, argument
+.I rot
+represents the desired absolute page orientation.
+Only DjVu pages can be rotated.
+Pages represented as a raw IW44 image cannot be rotated.
 .TP
 .BI "set-page-title " "title"
 Sets a page title for the selected page.
--- djvulibre-3.5.25.4.orig/tools/djvused.cpp
+++ djvulibre-3.5.25.4/tools/djvused.cpp
@@ -550,36 +550,47 @@ command_dump(ParsingByteStream &)
 static void
 print_size(const GP<DjVuFile> &file)
 {
-  const GP<ByteStream> pbs(file->get_djvu_bytestream(false, false));
-  const GP<IFFByteStream> iff(IFFByteStream::create(pbs));
-  GUTF8String chkid;
-  if (! iff->get_chunk(chkid))
-    verror("Selected file contains no data");
-  if (chkid == "FORM:DJVU")
+  GP<DjVuInfo> info = file->info;
+  if (! info)
     {
-      while (iff->get_chunk(chkid) && chkid!="INFO")
-        iff->close_chunk();
-      if (chkid == "INFO")
+      const GP<ByteStream> pbs(file->get_djvu_bytestream(false, false));
+      const GP<IFFByteStream> iff(IFFByteStream::create(pbs));
+      GUTF8String chkid;
+      if (! iff->get_chunk(chkid))
+        verror("Selected file contains no data");
+      if (chkid == "FORM:DJVU")
+        {
+          while (iff->get_chunk(chkid) && chkid!="INFO")
+            iff->close_chunk();
+          if (chkid == "INFO")
+            { 
+              info = DjVuInfo::create();
+              info->decode(*iff->get_bytestream());
+            }
+        }
+      else if (chkid == "FORM:BM44" || chkid == "FORM:PM44")
         {
-          GP<DjVuInfo> info=DjVuInfo::create();
-          info->decode(*iff->get_bytestream());
-          fprintf(stdout,"width=%d height=%d\n", info->width, info->height);
+          while (iff->get_chunk(chkid) && chkid!="BM44" && chkid!="PM44")
+            iff->close_chunk();
+          if (chkid=="BM44" || chkid=="PM44")
+            {
+              GP<IW44Image> junk=IW44Image::create_decode(IW44Image::COLOR);
+              junk->decode_chunk(iff->get_bytestream());
+              fprintf(stdout,"width=%d height=%d\n", 
+                      junk->get_width(), junk->get_height());
+            }
         }
     }
-  else if (chkid == "FORM:BM44" || chkid == "FORM:PM44")
+  if (info)
     {
-      while (iff->get_chunk(chkid) && chkid!="BM44" && chkid!="PM44")
-        iff->close_chunk();
-      if (chkid=="BM44" || chkid=="PM44")
-        {
-          GP<IW44Image> junk=IW44Image::create_decode(IW44Image::COLOR);
-          junk->decode_chunk(iff->get_bytestream());
-          fprintf(stdout,"width=%d height=%d\n", 
-                  junk->get_width(), junk->get_height());
-        }
+      fprintf(stdout,"width=%d height=%d", info->width, info->height);
+      if (info->orientation)
+        fprintf(stdout, " rotation=%d", info->orientation);
+      fprintf(stdout,"\n");
     }
 }
 
+
 void
 command_size(ParsingByteStream &)
 {
@@ -757,6 +768,72 @@ command_set_page_title(ParsingByteStream
   modified = true;
 }
 
+bool
+set_rotation(GP<DjVuFile> file, int rot, bool relative)
+{
+  // decode info
+  GP<DjVuInfo> info = file->info;
+  if (! info)
+    {
+      const GP<ByteStream> pbs(file->get_djvu_bytestream(false, false));
+      const GP<IFFByteStream> iff(IFFByteStream::create(pbs));
+      GUTF8String chkid;
+      if (! iff->get_chunk(chkid))
+        return false;
+      if (chkid == "FORM:DJVU")
+        {
+          while (iff->get_chunk(chkid) && chkid!="INFO")
+            iff->close_chunk();
+          if (chkid == "INFO")
+            {
+              info = DjVuInfo::create();
+              info->decode(*iff->get_bytestream());
+            }
+        }
+      file->info = info;
+    }
+  if (! info)
+    return false;
+  if (relative)
+    rot += info->orientation;
+  info->orientation = rot & 3;
+  file->set_modified(true);
+  modified = true;
+  return true;
+}
+
+void
+command_set_rotation(ParsingByteStream &pbs)
+{
+  GUTF8String rot = pbs.get_token();
+  if (! rot.is_int())
+    verror("usage: set-rotation [+-]<rot>");
+  int rotation = rot.toInt();
+  bool relative = (rot[0]=='+' || rot[0]=='-');
+  if (! relative)
+    if (rotation < 0 || rotation > 3)
+      verror("absolute rotation must be in range 0..3");
+  int rcount = 0;
+  if (g().file)
+    {
+      GUTF8String id = g().fileid;
+      if (set_rotation(g().file, rotation, relative))
+        rcount += 1;
+    }
+  else
+    {
+      GPList<DjVmDir::File> &lst = g().selected;
+      for (GPosition p=lst; p; ++p)
+        {
+          GUTF8String id = lst[p]->get_load_name();
+          const GP<DjVuFile> f(g().doc->get_djvu_file(id));
+          if (set_rotation(f, rotation, relative))
+            rcount += 1;
+        }
+    }
+  vprint("rotated %d pages", rcount);
+}
+
 
 #define DELMETA     1
 #define DELXMP      8
@@ -2030,6 +2107,7 @@ command_help(void)
           " . set-xmp [<xmpfile>]    -- copies <xmpfile> into the xmp metadata annotation tag\n" 
           " _ set-outline [<bmfile>] -- sets outline (bootmarks)\n"
           " _ set-thumbnails [<sz>]  -- generates all thumbnails with given size\n"
+          "   set-rotation [+-]<rot> -- sets page rotation\n"
           "   remove-ant             -- removes annotations\n"
           "   remove-meta            -- removes metadatas without changing other annotations\n"
           "   remove-txt             -- removes hidden text\n"
@@ -2097,6 +2175,7 @@ static GMap<GUTF8String,CommandFunc> &co
     xcommand_map["set-outline"] = command_set_outline;
     xcommand_map["set-xmp"] = command_set_xmp;
     xcommand_map["set-thumbnails"] = command_set_thumbnails;
+    xcommand_map["set-rotation"] = command_set_rotation;
     xcommand_map["remove-ant"] = command_remove_ant;
     xcommand_map["remove-meta"] = command_remove_meta;
     xcommand_map["remove-txt"] = command_remove_txt;
@@ -2207,7 +2286,7 @@ main(int argc, char **argv)
             utf8 = true;
           else if (!strcmp(argv[i],"-f") && i+1<argc && !g().cmdbs) 
             g().cmdbs = ByteStream::create(GURL::Filename::UTF8(GNativeString(argv[++i])), "r");
-          else if (!strcmp(argv[i],"-e") && !g().cmdbs && ++i<argc) 
+          else if (!strcmp(argv[i],"-e") && !g().cmdbs && i+1<argc && ++i) 
             g().cmdbs = ByteStream::create_static(argv[i],strlen(argv[i]));
           else if (argv[i][0] != '-' && !g().djvufile)
             g().djvufile = GNativeString(argv[i]);
