Exemplo n.º 1
0
void
test_attachment_save (void)
{
  GList *attachments, *node;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  attachments = poppler_document_get_attachments (document);
  gcut_take_list (attachments, attachment_unref);
  for (node = attachments; node; node = g_list_next (node))
    {
      PopplerAttachment *attachment = node->data;
      const gchar *filename;
      gchar *contents;
      const gchar *expected_contents;
      GError *error = NULL;

      filename = cut_take_string (g_build_filename (tmp_dir,
                                                    attachment->name,
                                                    NULL));
      poppler_attachment_save (attachment, filename, &error);
      gcut_assert_error (error);

      g_file_get_contents (filename, &contents, NULL, &error);
      gcut_assert_error (error);
      expected_contents = cut_get_fixture_data_string (attachment->name, NULL);
      cut_set_message ("%s", attachment->name);
      cut_assert_equal_string_with_free (expected_contents, contents);
    }
}
Exemplo n.º 2
0
void
test_font (void)
{
  PopplerFontInfo *font_info;
  PopplerFontsIter *iter;
  gint n_pages;

  document = load_document ("slide.pdf");
  n_pages = poppler_document_get_n_pages (document);
  font_info = poppler_font_info_new (document);
  while (poppler_font_info_scan (font_info, n_pages, &iter))
    {
      if (iter)
        {
          do
            {
              actual_font_names =
                g_list_append (actual_font_names,
                               g_strdup (poppler_fonts_iter_get_name (iter)));
            } while (poppler_fonts_iter_next (iter));
          poppler_fonts_iter_free (iter);
        }
    }
  g_object_unref (font_info);

  expected_font_names = gcut_list_string_new ("IPAPMincho",
                                              "LiberationSans-Regular",
                                              NULL);
  gcut_assert_equal_list_string (expected_font_names,
                                 actual_font_names);
}
Exemplo n.º 3
0
void
test_property (void)
{
  gint gmt_creation_date, local_creation_date;
  struct tm *local_time;
  time_t base, tz_diff;

  time (&base);
  local_time = localtime (&base);
  tz_diff = mktime (local_time) - mktime (gmtime (&base));
  if (local_time->tm_isdst)
    tz_diff += 3600;

  gmt_creation_date = 1223848360;
  local_creation_date = gmt_creation_date - tz_diff;
  document = load_document ("property.pdf");
  cut_poppler_assert_equal_property ("Property Document", "PDF-1.4", NULL,
                                     "property", "property, test",
                                     local_creation_date, 0,
                                     "Writer", "OpenOffice.org 2.4",
                                     "No",
                                     POPPLER_PAGE_MODE_USE_THUMBS,
                                     POPPLER_PAGE_LAYOUT_UNSET,
                                     0,
                                     POPPLER_PERMISSIONS_FULL,
                                     document);
}
Exemplo n.º 4
0
TEST(File, SeveralSizes)
{
  she::ScopedHandle<she::System> system(she::CreateSystem());
  // Register all possible image formats.
  FileFormatsManager::instance().registerAllFormats();
  std::vector<char> fn(256);

  for (int w=10; w<=10+503*2; w+=503) {
    for (int h=10; h<=10+503*2; h+=503) {
      //std::sprintf(&fn[0], "test_%dx%d.ase", w, h);
      std::sprintf(&fn[0], "test.ase");

      {
        UniquePtr<Document> doc(Document::createBasicDocument(IMAGE_INDEXED, w, h, 256));
        doc->setFilename(&fn[0]);

        // Random pixels
        LayerImage* layer = dynamic_cast<LayerImage*>(doc->getSprite()->getFolder()->getFirstLayer());
        ASSERT_TRUE(layer != NULL);
        Image* image = doc->getSprite()->getStock()->getImage(layer->getCel(FrameNumber(0))->getImage());
        std::srand(w*h);
        int c = std::rand()%256;
        for (int y=0; y<h; y++) {
          for (int x=0; x<w; x++) {
            image_putpixel_fast<IndexedTraits>(image, x, y, c);
            if ((std::rand()&4) == 0)
              c = std::rand()%256;
          }
        }

        save_document(doc);
      }

      {
        UniquePtr<Document> doc(load_document(&fn[0]));
        ASSERT_EQ(w, doc->getSprite()->getWidth());
        ASSERT_EQ(h, doc->getSprite()->getHeight());

        // Same random pixels (see the seed)
        LayerImage* layer = dynamic_cast<LayerImage*>(doc->getSprite()->getFolder()->getFirstLayer());
        ASSERT_TRUE(layer != NULL);
        Image* image = doc->getSprite()->getStock()->getImage(layer->getCel(FrameNumber(0))->getImage());
        std::srand(w*h);
        int c = std::rand()%256;
        for (int y=0; y<h; y++) {
          for (int x=0; x<w; x++) {
            ASSERT_EQ(c, image_getpixel_fast<IndexedTraits>(image, x, y));
            if ((std::rand()&4) == 0)
              c = std::rand()%256;
          }
        }
      }
    }
  }
}
Exemplo n.º 5
0
  virtual Arabica::XPath::NodeSet<std::string> doEvaluate(const DOM::Node<std::string>& context,
                                                          const Arabica::XPath::ExecutionContext<std::string>& executionContext) const
  {
    Arabica::XPath::NodeSet<std::string> nodes;
     
    Arabica::XPath::XPathValue<std::string> a0 = arg(0, context, executionContext);
    if(argCount() != 1)
      throw Arabica::XPath::UnsupportedException("two arg version of document()");
    if(a0.type() != Arabica::XPath::STRING)
      throw Arabica::XPath::UnsupportedException("node-set arg version of document()");

    load_document(a0.asString(), nodes);
    return nodes;
  } // doEvaluate
Exemplo n.º 6
0
void
test_save_a_copy (void)
{
  GError *error = NULL;
  gchar *copy_path;
  const gchar *copy_uri;

  document = load_document ("multi-pages.pdf");
  cut_assert_equal_int (3, poppler_document_get_n_pages (document));

  copy_path = g_build_filename (tmp_dir, "copied-multi-pages.pdf", NULL);
  copy_uri = cut_take_printf ("file://%s", copy_path);
  g_free (copy_path);

  poppler_document_save_a_copy (document, copy_uri, &error);
  gcut_assert_error (error);

  g_object_unref (document);
  document = poppler_document_new_from_file (copy_uri, NULL, &error);
  gcut_assert_error (error);
  cut_assert_equal_int (3, poppler_document_get_n_pages (document));
}
Exemplo n.º 7
0
void
test_action (void)
{
  PopplerIndexIter *iter;

  document = load_document ("slide.pdf");
  iter = poppler_index_iter_new (document);
  cut_assert_not_null (iter);

  collect_action (iter);
  poppler_index_iter_free (iter);

#define APPEND(type)                                                    \
  expected_action_types =                                               \
    g_list_append (expected_action_types, GINT_TO_POINTER (type))

  APPEND(POPPLER_ACTION_GOTO_DEST);
  APPEND(POPPLER_ACTION_GOTO_DEST);
#undef APPEND

  gcut_assert_equal_list_enum (POPPLER_TYPE_ACTION_TYPE,
                               expected_action_types, actual_action_types);
}
Exemplo n.º 8
0
void
test_attachment (void)
{
  GList *expected = NULL, *actual;

  document = load_document ("attachment.pdf");
  cut_assert_true (poppler_document_has_attachments (document));

  expected = g_list_append (expected,
                            attachment_new ("hello.html", "hello.html", 300,
                                            0, 0, NULL));
  expected = g_list_append (expected,
                            attachment_new ("hello.txt", "hello.txt", 13,
                                            0, 0, NULL));

  actual = poppler_document_get_attachments (document);
  gcut_take_list (expected, attachment_unref);
  gcut_take_list (actual, attachment_unref);
  gcut_assert_equal_list (expected,
                          actual,
                          attachment_equal,
                          attachment_inspect,
                          NULL);
}
Exemplo n.º 9
0
void
test_no_attachment (void)
{
  document = load_document ("empty.pdf");
  cut_assert_false (poppler_document_has_attachments (document));
}
Exemplo n.º 10
0
int App::run()
{
#ifdef ENABLE_UPDATER
  app::CheckUpdateThreadLauncher checkUpdate;
#endif

  // Initialize GUI interface
  if (isGui()) {
    View* view;
    Editor* editor;

    PRINTF("GUI mode\n");

    // Setup the GUI screen
    jmouse_set_cursor(JI_CURSOR_NORMAL);
    gui::Manager::getDefault()->invalidate();

    // Load main window
    top_window = static_cast<Frame*>(load_widget("main_window.xml", "main_window"));

    box_menubar = top_window->findChild("menubar");
    box_editors = top_window->findChild("editor");
    box_colorbar = top_window->findChild("colorbar");
    box_toolbar = top_window->findChild("toolbar");
    box_statusbar = top_window->findChild("statusbar");
    box_tabsbar = top_window->findChild("tabsbar");

    menubar = new MenuBar();
    statusbar = new StatusBar();
    colorbar = new ColorBar(box_colorbar->getAlign());
    toolbar = toolbar_new();
    tabsbar = new Tabs(m_tabsDelegate = new AppTabsDelegate());
    view = new EditorView(EditorView::CurrentEditorMode);
    editor = create_new_editor();

    // configure all widgets to expansives
    menubar->setExpansive(true);
    statusbar->setExpansive(true);
    colorbar->setExpansive(true);
    toolbar->setExpansive(true);
    tabsbar->setExpansive(true);
    view->setExpansive(true);

    /* prepare the first editor */
    view->attachToView(editor);

    /* setup the menus */
    menubar->setMenu(get_root_menu());

    /* start text of status bar */
    app_default_statusbar_message();

    /* add the widgets in the boxes */
    if (box_menubar) box_menubar->addChild(menubar);
    if (box_editors) box_editors->addChild(view);
    if (box_colorbar) box_colorbar->addChild(colorbar);
    if (box_toolbar) box_toolbar->addChild(toolbar);
    if (box_statusbar) box_statusbar->addChild(statusbar);
    if (box_tabsbar) box_tabsbar->addChild(tabsbar);

    /* prepare the window */
    top_window->remap_window();

    // Create the list of tabs
    app_rebuild_documents_tabs();
    app_rebuild_recent_list();

    // Set current editor
    set_current_editor(editor);

    // Open the window
    top_window->open_window();

    // Redraw the whole screen.
    gui::Manager::getDefault()->invalidate();
  }

  /* set background mode for non-GUI modes */
/*   if (!(ase_mode & MODE_GUI)) */
/*     set_display_switch_mode(SWITCH_BACKAMNESIA); */
    set_display_switch_mode(SWITCH_BACKGROUND);

    // procress options
  PRINTF("Processing options...\n");

  ASSERT(m_checkArgs != NULL);
  {
    Console console;
    for (CheckArgs::iterator
           it  = m_checkArgs->begin();
         it != m_checkArgs->end(); ++it) {
      CheckArgs::Option* option = *it;

      switch (option->type()) {

        case CheckArgs::Option::OpenSprite: {
          // Load the sprite
          Document* document = load_document(option->data().c_str());
          if (!document) {
            if (!isGui())
              console.printf("Error loading file \"%s\"\n", option->data().c_str());
          }
          else {
            // Mount and select the sprite
            UIContext* context = UIContext::instance();
            context->addDocument(document);
            context->setActiveDocument(document);

            if (isGui()) {
              // Show it
              set_document_in_more_reliable_editor(context->getFirstDocument());

              // Recent file
              getRecentFiles()->addRecentFile(option->data().c_str());
            }
          }
          break;
        }
      }
    }
    delete m_checkArgs;
    m_checkArgs = NULL;
  }

  // Run the GUI
  if (isGui()) {
    // Support to drop files from Windows explorer
    install_drop_files();

#ifdef ENABLE_UPDATER
    // Launch the thread to check for updates.
    checkUpdate.launch();
#endif

    // Run the GUI main message loop
    gui_run();

    // Uninstall support to drop files
    uninstall_drop_files();

    // Remove the root-menu from the menu-bar (because the rootmenu
    // module should destroy it).
    menubar->setMenu(NULL);

    // Delete all editors first because they used signals from other
    // widgets (e.g. color bar).
    delete box_editors;

    // Destroy mini-editor.
    exit_module_editors();

    // Destroy the top-window
    delete top_window;
    top_window = NULL;
  }

  return 0;
}