Changeset 22

Show
Ignore:
Timestamp:
04/11/06 09:02:28 (2 years ago)
Author:
jordi
Message:

I've moved all Get*() functions (metadata: title, author, ...) from PDFDocument to IDocument and also created a setter for function for each of them.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/PDFDocument.cxx

    r21 r22  
    4141    IDocument () 
    4242{ 
    43     m_Author = NULL; 
    44     m_CreationDate = NULL; 
    45     m_Creator = NULL; 
    4643    m_Document = NULL; 
    47     m_Format = NULL; 
    48     m_Keywords = NULL; 
    49     m_Linearized = NULL; 
    50     m_ModifiedDate = NULL; 
    5144    m_OutputDevice = NULL; 
    52     m_PageLayout = PageLayoutUnset; 
    53     m_PageMode = PageModeUnset; 
    54     m_PageNumber = 0; 
    55     m_Producer = NULL; 
    56     m_Subject = NULL; 
    57     m_Title = NULL; 
    5845} 
    5946 
     
    6552    delete m_Document; 
    6653    delete m_OutputDevice; 
    67     g_free (m_Author); 
    68     g_free (m_CreationDate); 
    69     g_free (m_Creator); 
    70     g_free (m_Format); 
    71     g_free (m_Keywords); 
    72     g_free (m_Linearized); 
    73     g_free (m_ModifiedDate); 
    74     g_free (m_Producer); 
    75     g_free (m_Subject); 
    76     g_free (m_Title); 
    7754} 
    7855 
     
    153130 
    154131/// 
    155 /// @brief Gets the document's title. 
    156 /// 
    157 /// @return The title of the document or an empty string if the document don't 
    158 ///         have a title. 
    159 /// 
    160 const gchar * 
    161 PDFDocument::getTitle () 
    162 { 
    163     if ( NULL == m_Title ) 
    164     { 
    165         return ""; 
    166     } 
    167     return m_Title; 
    168 } 
    169  
    170 /// 
    171 /// @brief Gets the document's author. 
    172 /// 
    173 /// @return The author of the document or an empty string if the document don't 
    174 ///         have the author name. 
    175 /// 
    176 const gchar * 
    177 PDFDocument::getAuthor () 
    178 { 
    179     if ( NULL == m_Author ) 
    180     { 
    181         return ""; 
    182     } 
    183     return m_Author; 
    184 } 
    185  
    186 /// 
    187 /// @brief Gets the document's subject. 
    188 /// 
    189 /// @return The subject of the document or an empty string ig the document don't 
    190 ///         have subject. 
    191 /// 
    192 const gchar * 
    193 PDFDocument::getSubject () 
    194 { 
    195     if ( NULL == m_Subject ) 
    196     { 
    197         return ""; 
    198     } 
    199     return m_Subject; 
    200 } 
    201  
    202 /// 
    203 /// @brief Gets the document's keywords. 
    204 /// 
    205 /// @return An string with all keywords separated by whitespace, or an empty 
    206 ///         string if the document have no keywords. 
    207 /// 
    208 const gchar * 
    209 PDFDocument::getKeywords () 
    210 { 
    211     if ( NULL == m_Keywords ) 
    212     { 
    213         return ""; 
    214     } 
    215     return m_Keywords; 
    216 } 
    217  
    218 /// 
    219 /// @brief Gets the document's creator. 
    220 /// 
    221 /// @return The name of the software that created the document or an empty 
    222 ///         string if the creator's name is not available. 
    223 /// 
    224 const gchar * 
    225 PDFDocument::getCreator () 
    226 { 
    227     if ( NULL == m_Creator ) 
    228     { 
    229         return ""; 
    230     } 
    231     return m_Creator; 
    232 } 
    233  
    234 /// 
    235 /// @brief Gets the document's producer. 
    236 /// 
    237 /// @return The name of the software that converted the document or an empty 
    238 ///         string if the producer's name is not available. 
    239 /// 
    240 const gchar * 
    241 PDFDocument::getProducer () 
    242 { 
    243     if ( NULL == m_Producer ) 
    244     { 
    245         return ""; 
    246     } 
    247     return m_Producer; 
    248 } 
    249  
    250 /// 
    251 /// @brief Get the document's format. 
    252 /// 
    253 /// @returns The PDF version of the document or an empty string if the version 
    254 ///          is not available (usually only when the document has not been 
    255 ///          loaded yet). 
    256 /// 
    257 const gchar * 
    258 PDFDocument::getFormat () 
    259 { 
    260     if ( NULL == m_Format ) 
    261     {         
    262         return ""; 
    263     } 
    264     return m_Format; 
    265 } 
    266  
    267 /// 
    268 /// @brief Get if the document is linearized. 
    269 /// 
    270 /// @return The string "Yes" if the document is optimized for web viewing, "No" 
    271 ///         if it's not optimized or an empty string if this information is 
    272 ///         not available. 
    273 /// 
    274 const gchar * 
    275 PDFDocument::getLinearized () 
    276 { 
    277     if ( NULL == m_Linearized ) 
    278     { 
    279         return ""; 
    280     } 
    281     return m_Linearized;     
    282 } 
    283  
    284 /// 
    285 /// @brief Get the document's creation date. 
    286 /// 
    287 /// @return The date and time the document was created or an empty string if 
    288 ///         this information is not available. 
    289 /// 
    290 const gchar * 
    291 PDFDocument::getCreationDate () 
    292 { 
    293     if ( NULL == m_CreationDate ) 
    294     { 
    295         return ""; 
    296     } 
    297     return m_CreationDate; 
    298 } 
    299  
    300 /// 
    301 /// @brief Get the document's modification date. 
    302 /// 
    303 /// @return The date and time the document was modified or an empty string if 
    304 ///         this information is not available. 
    305 /// 
    306 const gchar * 
    307 PDFDocument::getModifiedDate () 
    308 { 
    309     if ( NULL == m_ModifiedDate ) 
    310     { 
    311         return ""; 
    312     } 
    313     return m_ModifiedDate; 
    314 } 
    315  
    316 /// 
    317 /// @brief Get the documents page mode. 
    318 /// 
    319 /// @return The page mode of the document or PageModeUnset if this 
    320 ///         information is not available. 
    321 /// 
    322 PageMode 
    323 PDFDocument::getPageMode () 
    324 { 
    325     return m_PageMode; 
    326 } 
    327  
    328 /// 
    329 /// @brief Get the document's page layout. 
    330 /// 
    331 /// @return The initial page layout of the document or PageLayoutUnset if this 
    332 ///         information is not available. 
    333 /// 
    334 PageLayout 
    335 PDFDocument::getPageLayout () 
    336 { 
    337     return m_PageLayout; 
    338 } 
    339  
    340 /// 
    341 /// @brief Get the document's number of pages. 
    342 /// 
    343 /// @return The total number of pages the document has or 0 if the document has 
    344 ///         not been loaded yet. 
    345 /// 
    346 gint 
    347 PDFDocument::getNumPages () 
    348 { 
    349     return m_PageNumber; 
    350 } 
    351  
    352 /// 
    353132/// @brief Read the document's metadata. 
    354133/// 
     
    366145    m_Document->getDocInfo (&dictionary); 
    367146 
    368     g_free (m_Author); 
    369     m_Author = getDictionaryString (dictionary, "Author"); 
    370     g_free (m_CreationDate); 
    371     m_CreationDate = getDictionaryDate (dictionary, "CreationDate"); 
    372     g_free (m_Creator); 
    373     m_Creator = getDictionaryString (dictionary, "Creator"); 
    374     g_free(m_Format); 
    375     m_Format = g_strdup_printf ("PDF-%.2g", m_Document->getPDFVersion ()); 
    376     g_free (m_Keywords); 
    377     m_Keywords = getDictionaryString (dictionary, "Keywords"); 
    378     g_free (m_Linearized); 
    379     if ( m_Document->isLinearized () ) 
    380     { 
    381         m_Linearized = g_strdup ("Yes"); 
    382     } 
    383     else 
    384     { 
    385         m_Linearized = g_strdup ("No"); 
    386     } 
    387     g_free (m_ModifiedDate); 
    388     m_ModifiedDate = getDictionaryDate (dictionary, "ModDate"); 
    389     g_free (m_Producer); 
    390     m_Producer = getDictionaryString (dictionary, "Producer"); 
    391     g_free (m_Subject); 
    392     m_Subject = getDictionaryString (dictionary, "Subject"); 
    393     g_free (m_Title); 
    394     m_Title = getDictionaryString (dictionary, "Title"); 
     147    gchar *value = NULL; 
     148    // Author 
     149    value = getDictionaryString (dictionary, "Author"); 
     150    setAuthor (value); 
     151    g_free (value); 
     152    // Creation date. 
     153    value = getDictionaryDate (dictionary, "CreationDate"); 
     154    setCreationDate (value); 
     155    g_free (value); 
     156    // Creator 
     157    value = getDictionaryString (dictionary, "Creator"); 
     158    setCreator (value); 
     159    g_free (value); 
     160    // PDF Format 
     161    value = g_strdup_printf ("PDF-%.2g", m_Document->getPDFVersion ()); 
     162    setFormat (value); 
     163    g_free (value); 
     164    // Keywords 
     165    value = getDictionaryString (dictionary, "Keywords"); 
     166    setKeywords (value); 
     167    g_free (value); 
     168    // Is linearized 
     169    setLinearized (m_Document->isLinearized ()); 
     170    // Modified date 
     171    value = getDictionaryDate (dictionary, "ModDate"); 
     172    setModifiedDate (value); 
     173    g_free (value); 
     174    // Producer 
     175    value = getDictionaryString (dictionary, "Producer"); 
     176    setProducer (value); 
     177    g_free (value); 
     178    // Subject 
     179    value = getDictionaryString (dictionary, "Subject"); 
     180    setSubject (value); 
     181    g_free (value); 
     182    // Title 
     183    value = getDictionaryString (dictionary, "Title"); 
     184    setTitle (value); 
     185    g_free (value); 
    395186 
    396187    // For the page mode and layout we need the catalog, not the 
    397188    // dictionary. 
    398189    Catalog *catalog = m_Document->getCatalog (); 
    399     m_PageLayout = convertPageLayout (catalog->getPageLayout ()); 
    400     m_PageMode = convertPageMode (catalog->getPageMode ()); 
     190    setPageLayout (convertPageLayout (catalog->getPageLayout ())); 
     191    setPageMode (convertPageMode (catalog->getPageMode ())); 
    401192 
    402193    // Get the number of pages and set the current to the first. 
    403     m_PageNumber = m_Document->getNumPages (); 
     194    setNumPages (m_Document->getNumPages ()); 
    404195    goToFirstPage (); 
    405196 
  • trunk/src/PDFDocument.h

    r21 r22  
    3838            gboolean loadFile (const gchar *filename, const gchar *password,  
    3939                           GError **error); 
    40             const gchar *getTitle (void); 
    41             const gchar *getAuthor (void); 
    42             const gchar *getSubject (void); 
    43             const gchar *getKeywords (void); 
    44             const gchar *getCreator (void); 
    45             const gchar *getProducer (void); 
    46             const gchar *getFormat (void); 
    47             const gchar *getLinearized (void); 
    48             const gchar *getCreationDate (void); 
    49             const gchar *getModifiedDate (void); 
    50             PageMode getPageMode (void); 
    51             PageLayout getPageLayout (void); 
    52             gint getNumPages (void); 
    53  
    5440            void getPageSize (gdouble *width, gdouble *height); 
    5541            DocumentPage *renderPage (void); 
     
    5743        protected: 
    5844            PDFDoc *m_Document; 
    59             // Output device 
    6045            CairoOutputDev *m_OutputDevice; 
    61             // Document's metadata. 
    62             gchar *m_Author; 
    63             gchar *m_CreationDate; 
    64             gchar *m_Creator; 
    65             gchar *m_Format; 
    66             gchar *m_Keywords; 
    67             gchar *m_Linearized; 
    68             gchar *m_ModifiedDate; 
    69             PageLayout m_PageLayout; 
    70             PageMode m_PageMode; 
    71             gint m_PageNumber; 
    72             gchar *m_Producer; 
    73             gchar *m_Subject; 
    74             gchar *m_Title; 
    7546 
    7647            void loadMetadata (void); 
    77  
    78             static GQuark errorQuark; 
    7948    }; 
    8049} 
  • trunk/tests/PDFDocumentTest.cxx

    r21 r22  
    7070            g_ascii_strcasecmp ("", m_Document->getFormat ())); 
    7171    CPPUNIT_ASSERT_EQUAL (0,  
    72             g_ascii_strcasecmp ("", m_Document->getLinearized ())); 
     72            g_ascii_strcasecmp ("No", m_Document->getLinearized ())); 
    7373    CPPUNIT_ASSERT_EQUAL (0,  
    7474            g_ascii_strcasecmp ("", m_Document->getCreationDate ()));