Home | History | Annotate | Download | only in printing
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef PRINTING_PAGE_NUMBER_H_
      6 #define PRINTING_PAGE_NUMBER_H_
      7 
      8 #include <ostream>
      9 
     10 #include "printing/page_range.h"
     11 
     12 namespace printing {
     13 
     14 class PrintSettings;
     15 
     16 // Represents a page series following the array of page ranges defined in a
     17 // PrintSettings.
     18 class PRINTING_EXPORT PageNumber {
     19  public:
     20   // Initializes the page to the first page in the settings's range or 0.
     21   PageNumber(const PrintSettings& settings, int document_page_count);
     22 
     23   PageNumber();
     24 
     25   void operator=(const PageNumber& other);
     26 
     27   // Initializes the page to the first page in the setting's range or 0. It
     28   // initialize to npos if the range is empty and document_page_count is 0.
     29   void Init(const PrintSettings& settings, int document_page_count);
     30 
     31   // Converts to a page numbers.
     32   int ToInt() const {
     33     return page_number_;
     34   }
     35 
     36   // Calculates the next page in the serie.
     37   int operator++();
     38 
     39   // Returns an instance that represents the end of a serie.
     40   static const PageNumber npos() {
     41     return PageNumber();
     42   }
     43 
     44   // Equality operator. Only the current page number is verified so that
     45   // "page != PageNumber::npos()" works.
     46   bool operator==(const PageNumber& other) const;
     47   bool operator!=(const PageNumber& other) const;
     48 
     49  private:
     50   // The page range to follow.
     51   const PageRanges* ranges_;
     52 
     53   // The next page to be printed. -1 when not printing.
     54   int page_number_;
     55 
     56   // The next page to be printed. -1 when not used. Valid only if
     57   // document()->settings().range.empty() is false.
     58   int page_range_index_;
     59 
     60   // Number of expected pages in the document. Used when ranges_ is NULL.
     61   int document_page_count_;
     62 };
     63 
     64 // Debug output support.
     65 template<class E, class T>
     66 inline typename std::basic_ostream<E,T>& operator<<(
     67     typename std::basic_ostream<E,T>& ss, const PageNumber& page) {
     68   return ss << page.ToInt();
     69 }
     70 
     71 }  // namespace printing
     72 
     73 #endif  // PRINTING_PAGE_NUMBER_H_
     74