### Install Kimgio Desktop Files Source: https://github.com/graphics/okular/blob/master/generators/kimgio/CMakeLists.txt Installs the Kimgio desktop entry files to the appropriate KDE installation directory based on whether desktop or mobile builds are enabled. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_kimgio.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_kimgio.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-kimgio.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Desktop and Metadata Files Source: https://github.com/graphics/okular/blob/master/generators/comicbook/CMakeLists.txt Defines installation paths for desktop files and AppStream metadata. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_comicbook.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_comicbook.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-comicbook.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Desktop Files Conditionally Source: https://github.com/graphics/okular/blob/master/generators/markdown/CMakeLists.txt Installs the desktop entry file for the Okular Markdown generator. The installation path depends on whether the BUILD_DESKTOP or BUILD_MOBILE flag is enabled. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_md.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_md.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() ``` -------------------------------- ### Install CMake Configuration Files Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs the generated CMake configuration files (Okular6Config.cmake and Okular6ConfigVersion.cmake) to the installation directory. These files are typically installed as part of the 'Devel' component. ```cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/Okular6Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/Okular6ConfigVersion.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel ) ``` -------------------------------- ### Install Desktop and Metainfo Files Source: https://github.com/graphics/okular/blob/master/generators/mobipocket/CMakeLists.txt Installs desktop files based on build targets and the metainfo XML file. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_mobi.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_mobi.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-mobipocket.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Desktop and Metadata Files Source: https://github.com/graphics/okular/blob/master/generators/fictionbook/CMakeLists.txt Handles the installation of desktop files and metadata based on build configuration flags. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_fb.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_fb.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-fb.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Okular Kirigami Targets Source: https://github.com/graphics/okular/blob/master/mobile/app/CMakeLists.txt Installs the Okular Kirigami executable and associated desktop files. This ensures the application is correctly placed in the system's installation directories. ```cmake install(TARGETS okularkirigami ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) install(FILES package/metadata.desktop DESTINATION ${KDE_INSTALL_APPDIR} RENAME org.kde.okular.kirigami.desktop) install(FILES org.kde.okular.kirigami.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Generator Files Source: https://github.com/graphics/okular/blob/master/generators/tiff/CMakeLists.txt Installs desktop and metainfo files based on the build target platform. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_tiff.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_tiff.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-tiff.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install DVI Generator Files Source: https://github.com/graphics/okular/blob/master/generators/dvi/CMakeLists.txt Defines installation paths for desktop files and metadata based on build configuration. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_dvi.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_dvi.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-dvi.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install EPUB Generator Files Source: https://github.com/graphics/okular/blob/master/generators/epub/CMakeLists.txt Installs desktop files for desktop or mobile builds and the metainfo XML file. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_epub.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_epub.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-epub.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Icons Source: https://github.com/graphics/okular/blob/master/generators/fictionbook/CMakeLists.txt Installs application icons into the hicolor theme directory. ```cmake ecm_install_icons(ICONS 16-apps-okular-fb2.png 32-apps-okular-fb2.png 48-apps-okular-fb2.png DESTINATION ${KDE_INSTALL_DATADIR}/okular/icons THEME hicolor) ``` -------------------------------- ### Install DJVU Generator Files Source: https://github.com/graphics/okular/blob/master/generators/djvu/CMakeLists.txt Installs desktop and metainfo files based on the build target platform. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_djvu.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_djvu.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-djvu.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Desktop Entry Files Source: https://github.com/graphics/okular/blob/master/generators/txt/CMakeLists.txt Installs desktop entry files for Okular based on build configuration (desktop or mobile). ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_txt.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_txt.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-txt.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Desktop Files for Okular XPS Source: https://github.com/graphics/okular/blob/master/generators/xps/CMakeLists.txt Installs desktop integration files for the Okular XPS generator based on build configurations for desktop and mobile platforms. The metainfo file is always installed. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_xps.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_xps.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() install( FILES org.kde.okular-xps.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Metainfo File Source: https://github.com/graphics/okular/blob/master/generators/markdown/CMakeLists.txt Installs the metainfo XML file for the Okular Markdown generator to the appropriate system directory. This file provides metadata about the application. ```cmake install( FILES org.kde.okular-md.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Metainfo File Source: https://github.com/graphics/okular/blob/master/generators/fax/CMakeLists.txt Installs the metainfo XML file for the fax generator. This file provides metadata for application stores and discovery services. ```cmake install( FILES org.kde.okular-fax.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Set Environment Variables for Custom Install Source: https://github.com/graphics/okular/blob/master/README.md Required command to ensure the system picks up the correct Okular instance and libraries when installed in a non-standard directory. ```bash source prefix.sh ``` -------------------------------- ### Install Localization Files Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs localization (po) files. It uses 'ki18n_install' and conditionally 'kdoctools_install' if KF6DocTools is found, ensuring proper internationalization support. ```cmake ki18n_install(po) if(KF6DocTools_FOUND) kdoctools_install(po) endif() ``` -------------------------------- ### Install Okular Part Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs the 'okularpart' target to a specific plugin directory. This ensures the part is discoverable by the system. ```cmake install(TARGETS okularpart DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf6/parts/ ) ``` -------------------------------- ### Configure CMake Installation for Generator Plugin Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Use these CMake commands to install the generator plugin and associated desktop/metainfo files. ```cmake install( TARGETS okularGenerator_magic DESTINATION ${PLUGIN_INSTALL_DIR} ) ########### install files ############### install( FILES okularMagic.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) install( PROGRAMS okularApplication_magic.desktop org.kde.mobile.okular_magic.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) install( FILES org.kde.okular-magic.metainfo.xml DESTINATION ${KDE_INSTALL_METAINFODIR} ) ``` -------------------------------- ### Install Okular Categories File Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs the 'okular.categories' file to the KDE logging categories directory. This is used for categorizing logging output. ```cmake install(FILES okular.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}) ``` -------------------------------- ### Install Annotation Page Images Source: https://github.com/graphics/okular/blob/master/part/data/CMakeLists.txt Installs various PNG images used on annotation pages. These are also placed in the Okular data directory's 'pics' subdirectory. ```cmake install(FILES checkmark.png circle.png comment.png cross.png help.png insert.png key.png newparagraph.png note.png paperclip.png paragraph.png pushpin.png rightarrow.png rightpointer.png star.png uparrow.png upleftarrow.png DESTINATION ${KDE_INSTALL_DATADIR}/okular/pics) ``` -------------------------------- ### Install Annotator XML Tools Source: https://github.com/graphics/okular/blob/master/part/data/CMakeLists.txt Installs XML files for annotator tools. Ensure the DESTINATION path is correctly set for Okular's data directory. ```cmake install(FILES tools.xml toolsQuick.xml drawingtools.xml DESTINATION ${KDE_INSTALL_DATADIR}/okular) ``` -------------------------------- ### Install Annotation Tool Images Source: https://github.com/graphics/okular/blob/master/part/data/CMakeLists.txt Installs PNG images used by annotation tools. These images are placed in the Okular data directory's 'pics' subdirectory. ```cmake install(FILES tool-base-okular.png tool-base-okular@2x.png tool-highlighter-okular-colorizable.png tool-highlighter-okular-colorizable@2x.png tool-ink-okular-colorizable.png tool-ink-okular-colorizable@2x.png tool-note.png tool-note-okular-colorizable.png tool-note-okular-colorizable@2x.png tool-note-inline.png tool-note-inline-okular-colorizable.png tool-note-inline-okular-colorizable@2x.png tool-typewriter-okular-colorizable.png tool-typewriter-okular-colorizable@2x.png DESTINATION ${KDE_INSTALL_DATADIR}/okular/pics) ``` -------------------------------- ### Configure CMake Build System Source: https://github.com/graphics/okular/blob/master/Mainpage.dox The CMakeLists.txt file handles compilation and installation of the generator plugin. ```cmake add_definitions(-DTRANSLATION_DOMAIN="okular_magic") macro_optional_find_package(Okular) include_directories( ${OKULAR_INCLUDE_DIR} ${KF6_INCLUDE_DIR} ${QT_INCLUDES} ) ########### next target ############### set( okularGenerator_magic_PART_SRCS generator_magic.cpp ) target_link_libraries( okularGenerator_magic PRIVATE okularcore KF6::I18n KF6::KIOCore ) ``` -------------------------------- ### Install Desktop Files Conditionally Source: https://github.com/graphics/okular/blob/master/generators/fax/CMakeLists.txt Installs desktop files for the fax generator based on build configurations (Desktop or Mobile). This ensures the application is discoverable by the system. ```cmake if (BUILD_DESKTOP) install( PROGRAMS okularApplication_fax.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() if (BUILD_MOBILE) install( PROGRAMS org.kde.mobile.okular_fax.desktop DESTINATION ${KDE_INSTALL_APPDIR} ) endif() ``` -------------------------------- ### Install Stamp SVG File Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs the 'stamps.svg' file to the Okular data directory for pictures. This is likely used for UI elements or icons. ```cmake install(FILES core/stamps.svg DESTINATION ${KDE_INSTALL_DATADIR}/okular/pics) ``` -------------------------------- ### Install CMake Export File Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Installs the CMake export file 'Okular6Targets.cmake'. This file allows other projects to import Okular targets using the 'Okular::' namespace. ```cmake install(EXPORT Okular6Targets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE Okular6Targets.cmake NAMESPACE Okular::) ``` -------------------------------- ### Configure Package Configuration File Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Configures and installs CMake package configuration files for Okular6. This involves generating Okular6Config.cmake and Okular6ConfigVersion.cmake, which are essential for other projects to find and use Okular. ```cmake set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/Okular6") configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/Okular6Config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/Okular6Config.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) ``` -------------------------------- ### Configure Desktop Entry Files Source: https://github.com/graphics/okular/blob/master/Mainpage.dox These desktop files register the plugin with the system and Okular's internal service architecture. ```ini [Desktop Entry] MimeType=application/x-magic; Terminal=false Name=okular GenericName=Document Viewer Exec=okular %U Icon=okular Type=Application InitialPreference=7 Categories=Qt;KDE;Graphics;Viewer; NoDisplay=true X-KDE-Keywords=Magic ``` ```ini [Desktop Entry] Icon=okular Name=okular X-KDE-ServiceTypes=KParts/ReadOnlyPart X-KDE-Library=okularpart Type=Service MimeType=application/x-magic; ``` ```ini [Desktop Entry] MimeType=application/x-magic; Name=Reader GenericName=Document viewer Comment=Viewer for various types of documents TryExec=kpackagelauncherqml -a org.kde.mobile.okular Exec=kpackagelauncherqml -a org.kde.mobile.okular %u Terminal=false Icon=okular Type=Application Categories=Qt;KDE;Graphics;Office;Viewer; InitialPreference=2 NoDisplay=true X-KDE-Keywords=Magic ``` -------------------------------- ### Configure Kimgio Test Target Source: https://github.com/graphics/okular/blob/master/generators/kimgio/CMakeLists.txt Sets up the kimgiotest target, including source files, linking libraries, and compile definitions. This is conditionally enabled if testing is built and desktop support is available. ```cmake if(BUILD_TESTING AND BUILD_DESKTOP AND KF6KExiv2_FOUND) add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" ) set( kimgiotest_SRCS tests/kimgiotest.cpp ${CMAKE_SOURCE_DIR}/gui/pagepainter.cpp ${CMAKE_SOURCE_DIR}/gui/guiutils.cpp ${CMAKE_SOURCE_DIR}/gui/debug_ui.cpp ) ecm_add_test(${kimgiotest_SRCS} TEST_NAME "kimgiotest" LINK_LIBRARIES okularcore okularpart Qt6::Svg Qt6::Test) target_compile_definitions(kimgiotest PRIVATE -DGENERATOR_PATH="$") endif() ``` -------------------------------- ### Build Okular with CMake Source: https://github.com/graphics/okular/blob/master/README.md Standard sequence of commands to clone, configure, and build the Okular project. ```bash git clone https://invent.kde.org/graphics/okular.git cd okular mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=/path/to/your/install/dir .. make make install ``` -------------------------------- ### Implement TextPage Generation Logic Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Implementation details for initializing the generator feature and populating the Okular::TextPage object with normalized character coordinates. ```cpp #include ... MagicGenerator::MagicGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ) { setFeature( TextExtraction ); } bool MagicGenerator::canGenerateTextPage() const { return true; } void MagicGenerator::generateTextPage( Okular::Page *page, enum Okular::GenerationType ) { MagicDocument::TextInfo::List characters = mMagicDocument.textOfPage( page->number() ); if ( characters.isEmpty() ) return; Okular::TextPage *textPage = new Okular::TextPage; for ( int i = 0; i < characters.count(); ++i ) { qreal left = characters[ i ].xPos / page->width(); qreal top = characters[ i ].yPos / page->height(); qreal right = (characters[ i ].xPos + characters[ i ].width) / page->width(); qreal bottom = (characters[ i ].yPos + characters[ i ].height) / page->height(); textPage->append( characters[ i ].character, new Okular::NormalizedRect( left, top, right, bottom ) ); } page->setTextPage( textPage ); } ``` -------------------------------- ### Configure Build UI Target Source: https://github.com/graphics/okular/blob/master/README.md CMake flag to specify the desired UI target, such as desktop or mobile. ```bash cmake -DCMAKE_INSTALL_PREFIX=/path/to/your/install/dir -DOKULAR_UI=desktop .. ``` -------------------------------- ### Strikethrough Tag Workaround in Code Block Source: https://github.com/graphics/okular/blob/master/autotests/data/strikethrough.md This snippet demonstrates that strikethrough markdown (~~text~~) is ignored within a code block, as intended. No special setup is required beyond the markdown syntax itself. ```markdown ~~Strikethrough~~ should be ignored in a code block ``` -------------------------------- ### HTMLGenerator::loadDocument Implementation Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Loads an HTML document from a file, sets it into a QTextDocument, and prepares Okular Page objects. It also initializes document information and synopsis. ```cpp bool HTMLGenerator::loadDocument( const QString &fileName, QList &pages ) { QFile file( fileName ); if ( !file.open( QIODevice::ReadOnly ) ) { emit error( i18n( "Unable to open file" ), -1 ); return false; } const QString data = QString::fromUtf8( file.readAll() ); file.close(); mTextDocument = new QTextDocument; mTextDocument->setHtml( data ); mTextDocument->setPageSize( QSizeF( 600, 800 ) ); pages.resize( mTextDocument->pageCount() ); for ( int i = 0; i < mTextDocument->pageCount(); ++i ) { Okular::Page * page = new Okular::Page( i, 600, 800, Okular::Rotation0 ); pages[ i ] = page; } mDocumentInfo.set( "author", "Tobias Koenig", i18n( "Author" ) ); mDocumentInfo.set( "title", "The Art of Okular Plugin Development", i18n( "Title" ) ); Okular::DocumentViewport viewport = ... // get the viewport of the chapter QDomElement item = mDocumentSynopsis.createElement( "Chapter 1" ); item.setAttribute( "Viewport", viewport.toString() ); mDocumentSynopsis.appendChild( item ); viewport = ... // get the viewport of the subchapter QDomElement childItem = mDocumentSynopsis.createElement( "SubChapter 1.1" ); childItem.setAttribute( "Viewport", viewport.toString() ); item.appendChild( childItem ); return true; } ``` -------------------------------- ### Specify image dimensions with Markdown syntax Source: https://github.com/graphics/okular/blob/master/autotests/data/imageSizes.md Use the =WxH syntax after the image URL to define width, height, or both. ```markdown ![potato](potato.jpg =100x) ``` ```markdown ![potato](potato.jpg =x100) ``` ```markdown ![potato](potato.jpg =100x100) ``` ```markdown ![1500x300](1500x300.png =100x) ``` ```markdown ![1500x300](1500x300.png =x100) ``` ```markdown ![1500x300](1500x300.png =100x100) ``` ```markdown ![300x1500](300x1500.png =100x) ``` ```markdown ![300x1500](300x1500.png =x100) ``` ```markdown ![300x1500](300x1500.png =100x100) ``` -------------------------------- ### Print HTML Document with QPainter Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Iterates through pages of a QTextDocument and draws contents onto a KPrinter using QPainter. ```cpp bool HTMLGenerator::print( KPrinter &printer ) { QPainter p( &printer ); for ( int i = 0; i < mTextDocument->pageCount(); ++i ) { if ( i != 0 ) printer.newPage(); QRect rect( 0, i * 800, 600, 800 ); p.translate( QPoint( 0, i * -800 ) ); mTextDocument->drawContents( &p, rect ); } } ``` -------------------------------- ### Configure Okular XPS Generator Target Source: https://github.com/graphics/okular/blob/master/generators/xps/CMakeLists.txt Defines the source files for the Okular XPS generator and links necessary libraries. Ensure KF6::Archive, KF6::I18n, Qt6::PrintSupport, and Qt6::Xml are available. ```cmake set(okularGenerator_xps_SRCS generator_xps.cpp ) okular_add_generator(okularGenerator_xps ${okularGenerator_xps_SRCS}) target_link_libraries(okularGenerator_xps okularcore KF6::Archive KF6::I18n Qt6::PrintSupport Qt6::Xml) ``` -------------------------------- ### Configure DVI Generator Definitions Source: https://github.com/graphics/okular/blob/master/generators/dvi/CMakeLists.txt Sets translation domains and conditional FreeType definitions for the DVI generator build. ```cmake remove_definitions(-DTRANSLATION_DOMAIN="okular") add_definitions(-DTRANSLATION_DOMAIN="okular_dvi") #add_definitions(-DDEBUG_DVIRENDERER -DDEBUG_RENDER -DDEBUG_PRESCAN -DDEBUG_PSGS -DDEBUG_FONTPOOL) if (FREETYPE_FOUND) add_definitions(-DHAVE_FREETYPE) else (FREETYPE_FOUND) remove_definitions(-DHAVE_FREETYPE) endif (FREETYPE_FOUND) ``` -------------------------------- ### Configure EPUB Generator Build Source: https://github.com/graphics/okular/blob/master/generators/epub/CMakeLists.txt Sets the translation domain and adds the data subdirectory for the EPUB generator project. ```cmake remove_definitions(-DTRANSLATION_DOMAIN="okular") add_definitions(-DTRANSLATION_DOMAIN="okular_epub") add_subdirectory(data) ``` -------------------------------- ### Specify QML Sources for Okular Kirigami Source: https://github.com/graphics/okular/blob/master/mobile/app/CMakeLists.txt Lists the QML source files used by the Okular Kirigami application. These files define the user interface and QML logic. ```cmake ecm_target_qml_sources(okularkirigami SOURCES ui/Bookmarks.qml ui/CertificateViewerPage.qml ui/Main.qml ui/MainView.qml ui/OkularDrawer.qml ui/TableOfContents.qml ui/Thumbnails.qml ui/ThumbnailsBase.qml ui/TreeItem.qml ui/TreeViewDecoration.qml ui/Signatures.qml ui/SignaturePropertiesPage.qml ui/WelcomeView.qml ) ``` -------------------------------- ### Define DVI Generator Source Files Source: https://github.com/graphics/okular/blob/master/generators/dvi/CMakeLists.txt Lists the C++ source files required to build the DVI generator. ```cmake set(okularGenerator_dvi_SRCS generator_dvi.cpp bigEndianByteReader.cpp dviRenderer.cpp dviRenderer_draw.cpp dviRenderer_prescan.cpp dviRenderer_dr.cpp special.cpp dviFile.cpp dviPageInfo.cpp psgs.cpp # psheader.cpp # already included in psgs.cpp glyph.cpp TeXFont.cpp TeXFontDefinition.cpp vf.cpp TeXFont_PFB.cpp TeXFont_PK.cpp TeXFont_TFM.cpp util.cpp pageSize.cpp length.cpp fontEncoding.cpp fontEncodingPool.cpp fontMap.cpp fontpool.cpp dvisourcesplitter.cpp dviexport.cpp ) ``` -------------------------------- ### Define Export Formats Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Returns the list of supported export formats, defaulting to PlainText. ```cpp Okular::ExportFormat::List HTMLGenerator::exportFormats() const { return Okular::ExportFormat::standardFormat( Okular::ExportFormat::PlainText ); } ``` -------------------------------- ### Link Libraries for Markdown Generator Source: https://github.com/graphics/okular/blob/master/generators/markdown/CMakeLists.txt Links the 'okularGenerator_md' target with necessary libraries, including 'okularcore', 'KF6::I18n', and 'PkgConfig::Discount'. This ensures all dependencies are met for the generator to function. ```cmake target_link_libraries(okularGenerator_md PRIVATE okularcore KF6::I18n PkgConfig::Discount) ``` -------------------------------- ### HTMLGenerator::generateDocumentInfo Implementation Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Returns the document information. This method returns a pre-configured Okular::DocumentInfo object. ```cpp Okular::DocumentInfo HTMLGenerator::generateDocumentInfo( const QSet &keys ) const { return mDocumentInfo; } ``` -------------------------------- ### HTMLGenerator::generatePixmap Implementation Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Generates a pixmap for a requested page and size. It uses QPainter to draw the document content onto the pixmap, scaling it to fit the requested dimensions. ```cpp void HTMLGenerator::generatePixmap( Okular::PixmapRequest *request ) { QPixmap *pixmap = new QPixmap( request->width(), request->height() ); pixmap->fill( Qt::white ); QPainter p; p.begin( pixmap ); qreal width = request->width(); qreal height = request->height(); p.scale( width / 600, height / 800 ); const QRect rect( 0, request->pageNumber() * 800, 600, 800 ); p.translate( QPoint( 0, request->pageNumber() * -800 ) ); d->mDocument->drawContents( &p, rect ); p.end(); request->page()->setPixmap( request->id(), pixmap ); signalPixmapRequestDone( request ); } ``` -------------------------------- ### HTMLGenerator::generateDocumentSynopsis Implementation Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Returns the document synopsis, which contains the table of contents. It returns a pointer to the internal QDomDocument synopsis or null if it's empty. ```cpp const Okular::DocumentSynopsis* HTMLGenerator::generateDocumentSynopsis() { if ( !mDocumentSynopsis.hasChildNodes() ) return 0; else ``` -------------------------------- ### Configure Kimgio Generator Target Source: https://github.com/graphics/okular/blob/master/generators/kimgio/CMakeLists.txt Adds the kimgio generator target and links necessary libraries. It conditionally compiles definitions and links KExiv2 if the KExiv2Qt6 target is found. ```cmake okular_add_generator(okularGenerator_kimgio generator_kimgio.cpp) target_link_libraries(okularGenerator_kimgio okularcore KF6::I18n) if(TARGET KExiv2Qt6) target_compile_definitions(okularGenerator_kimgio PRIVATE -DWITH_KEXIV=1) target_link_libraries(okularGenerator_kimgio KExiv2Qt6) endif() ``` -------------------------------- ### Define Okular Kirigami Executable and Link Libraries Source: https://github.com/graphics/okular/blob/master/mobile/app/CMakeLists.txt Defines the main executable for Okular Kirigami and links against essential Qt6 and KF6 libraries. Ensure these libraries are available in your build environment. ```cmake set(CMAKE_AUTORCC ON) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/../../ ) add_executable(okularkirigami main.cpp) target_link_libraries(okularkirigami PRIVATE Qt6::Widgets Qt6::Qml KF6::I18n KF6::CoreAddons) ``` -------------------------------- ### Configure Okular QML Module with CMake Source: https://github.com/graphics/okular/blob/master/mobile/components/CMakeLists.txt Defines the QML module, registers source files, and links dependencies for the Okular plugin. ```cmake ecm_add_qml_module(okularplugin URI "org.kde.okular" VERSION 2.0 GENERATE_PLUGIN_SOURCE DEPENDENCIES org.kde.kirigami ) target_sources(okularplugin PRIVATE ${CMAKE_SOURCE_DIR}/gui/guiutils.cpp ${CMAKE_SOURCE_DIR}/gui/tocmodel.cpp ${CMAKE_SOURCE_DIR}/gui/signaturemodel.cpp ${CMAKE_SOURCE_DIR}/gui/signatureguiutils.cpp ${CMAKE_SOURCE_DIR}/gui/certificatemodel.cpp ${CMAKE_SOURCE_DIR}/gui/pagepainter.cpp ${CMAKE_SOURCE_DIR}/gui/debug_ui.cpp ${CMAKE_SOURCE_DIR}/gui/recentitemsmodel.cpp pageitem.cpp documentitem.cpp thumbnailitem.cpp okularsingleton.cpp types.cpp welcomeitem.cpp ) kconfig_add_kcfg_files(okularplugin GENERATE_MOC ${CMAKE_SOURCE_DIR}/conf/settings_mobile.kcfgc) ecm_target_qml_sources(okularplugin SOURCES DocumentView.qml ) ecm_target_qml_sources(okularplugin PRIVATE PATH private SOURCES private/PageView.qml ) target_link_libraries(okularplugin PRIVATE Qt6::Quick Qt6::Qml Qt6::Core Qt6::Xml Qt6::Svg KF6::Bookmarks KF6::I18n KF6::Service okularcore ) ecm_finalize_qml_module(okularplugin DESTINATION ${KDE_INSTALL_QMLDIR} EXPORT OkularTargets) ``` -------------------------------- ### Android Build Configuration for Okular Kirigami Source: https://github.com/graphics/okular/blob/master/mobile/app/CMakeLists.txt Configures build settings specifically for Android, including adding Android-specific sources and linking libraries required by androiddeployqt. This section ensures proper packaging of dependencies for Android deployment. ```cmake if (ANDROID) target_sources(okularkirigami PRIVATE android.cpp) # androiddeployqt only packages libraries needed by the main binary. # That is problematic because some of the libraries we need we only use in plugins # here we help androiddeployqt by linking those plugins dependencies # to the app. get_property(aux_list GLOBAL PROPERTY okular_generator_list) foreach(okular_generator ${aux_list}) get_target_property(okular_generator_dependencies ${okular_generator} LINK_LIBRARIES) target_link_libraries(okularkirigami PRIVATE ${okular_generator_dependencies}) endforeach() # Unfortunately gitlab CI for now doesn't use Craft so we need # to differentiate between gitlab CI and the binary factory if (ANDROID_LINK_EXTRA_LIBRARIES) message("Linking in extra libraries to help androiddeployqt") # androiddeployqt only packages libraries needed by the main binary. # the pdf/poppler generator links to poppler that links to NSS # and NSS has plugins. Here we link to those plugins so they get packaged pkg_check_modules(NSS "nss") target_link_directories(okularkirigami PRIVATE ${NSS_LIBRARY_DIRS}) target_link_libraries(okularkirigami PRIVATE -lsoftokn3 -lnssckbi -lfreebl3) endif() kirigami_package_breeze_icons(ICONS ${KIRIGAMI_ADDONS_ICONS} application-pkcs7-signature bookmark-remove bookmarks-organize dialog-close document-open help-about-symbolic okular view-preview view-table-of-contents-ltr ) ecm_add_android_apk(okularkirigami ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../android) endif() ``` -------------------------------- ### Configure Okular Text Generator Source: https://github.com/graphics/okular/blob/master/generators/txt/CMakeLists.txt Defines source files for the okularGenerator_txt and adds it as a generator. Links against necessary libraries. ```cmake set(okularGenerator_txt_SRCS generator_txt.cpp converter.cpp document.cpp ) okular_add_generator(okularGenerator_txt ${okularGenerator_txt_SRCS}) target_link_libraries(okularGenerator_txt okularcore Qt6::Core KF6::I18n) ``` -------------------------------- ### HTMLGenerator Implementation - Constructor and Destructor Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Implements the constructor and destructor for the HTMLGenerator class. The constructor initializes the QTextDocument pointer, and the destructor ensures it is deleted. ```cpp #include #include #include #include #include #include "htmlgenerator.h" #include K_PLUGIN_CLASS_WITH_JSON(HTMLGenerator, "libokularGenerator_html.json") HTMLGenerator::HTMLGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ), mTextDocument( 0 ) { } HTMLGenerator::~HTMLGenerator() { delete mTextDocument; } ``` -------------------------------- ### MagicGenerator Implementation: Loading and Page Creation Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Implements the core logic for loading a Magic document, creating Okular::Page objects for each page, and handling potential loading errors by emitting an error signal. ```cpp #include #include "magicgenerator.h" K_PLUGIN_CLASS_WITH_JSON(MagicGenerator, "libokularGenerator_magic.json") MagicGenerator::MagicGenerator( QObject *parent, const QVariantList &args ) : Okular::Generator( parent, args ) { } MagicGenerator::~MagicGenerator() { } bool MagicGenerator::loadDocument( const QString &fileName, QList &pages ) { if ( !mMagicDocument.loadDocument( fileName ) ) { emit error( i18n( "Unable to load document" ), -1 ); return false; } pagesVector.resize( mMagicDocument.numberOfPages() ); for ( int i = 0; i < mMagicDocument.numberOfPages(); ++i ) { const QSize size = mMagicDocument.pageSize( i ); Okular::Page * page = new Okular::Page( i, size.width(), size.height(), Okular::Rotation0 ); pages[ i ] = page; } return true; } bool MagicGenerator::doCloseDocument() { return true; } bool MagicGenerator::canGeneratePixmap() const { return true; } void MagicGenerator::generatePixmap( Okular::PixmapRequest *request ) { QImage image = mMagicDocument.pictureOfPage( request->pageNumber() ); image = image.scaled( request->width(), request->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation ); request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( image ) ) ); signalPixmapRequestDone( request ); } ``` -------------------------------- ### Configure Mobi Generator Target Source: https://github.com/graphics/okular/blob/master/generators/mobipocket/CMakeLists.txt Defines the source files, adds the generator target, and links necessary libraries. ```cmake set(okularGenerator_mobi_PART_SRCS mobidocument.cpp generator_mobi.cpp converter.cpp ) okular_add_generator(okularGenerator_mobi ${okularGenerator_mobi_PART_SRCS}) target_link_libraries(okularGenerator_mobi okularcore QMobipocket6 KF6::I18n Qt6::Gui) ``` -------------------------------- ### Set Library Output Directory Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Sets the output directory for library files for the 'okularpart' target. This is specific to KF6 parts. ```cmake set_target_properties(okularpart PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/kf6/parts) ``` -------------------------------- ### Export Document to File Source: https://github.com/graphics/okular/blob/master/Mainpage.dox Writes the document content to a specified file path if the format is plain text. ```cpp bool HTMLGenerator::exportTo( const QString &fileName, const Okular::ExportFormat &format ) { QFile file( fileName ); if ( !fileName.open( QIODevice::WriteOnly ) ) { emit error( i18n( "Unable to open file" ), -1 ); return false; } if ( format.mimeType()->name() == QLatin1String( "text/plain" ) ) file.writeBlock( mTextDocument->toPlainText().toUtf8() ); file.close(); return true; } ``` -------------------------------- ### Register Autotests Source: https://github.com/graphics/okular/blob/master/generators/comicbook/CMakeLists.txt Adds the comicbook test suite if building tests is enabled. ```cmake if(BUILD_TESTING) add_definitions( -DKDESRCDIR="${CMAKE_CURRENT_SOURCE_DIR}/" ) ecm_add_test(autotests/comicbooktest.cpp TEST_NAME "comicbooktest" LINK_LIBRARIES Qt6::Test KF6::CoreAddons okularcore okular_comicbook ) endif() ``` -------------------------------- ### Feature Summary and Build Messages Source: https://github.com/graphics/okular/blob/master/CMakeLists.txt Generates a feature summary and displays build-related messages. 'feature_summary' checks for required packages, and 'message' commands output build configuration details. ```cmake feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) message("-- Building Desktop User Interface: ${BUILD_DESKTOP}") message("-- Building Mobile Interface: ${BUILD_MOBILE}") message("") ``` -------------------------------- ### Generate QML Module for Okular Kirigami Source: https://github.com/graphics/okular/blob/master/mobile/app/CMakeLists.txt Generates a QML module for the Okular Kirigami application. This is essential for integrating QML components into the application. ```cmake ecm_add_qml_module(okularkirigami URI "org.kde.okular.app" GENERATE_PLUGIN_SOURCE ) ``` -------------------------------- ### Configure Generator Target Source: https://github.com/graphics/okular/blob/master/generators/fictionbook/CMakeLists.txt Defines the source files and links necessary libraries for the FictionBook generator. ```cmake set(okularGenerator_fb_PART_SRCS converter.cpp document.cpp generator_fb.cpp ) okular_add_generator(okularGenerator_fb ${okularGenerator_fb_PART_SRCS}) target_link_libraries(okularGenerator_fb okularcore KF6::Archive KF6::I18n Qt6::Xml) ```