@@ -197,10 +197,11 @@ void zathura_update_view_ppi(zathura_t* zathura) {
197
197
}
198
198
#endif
199
199
200
- const double current_ppi = zathura_document_get_viewport_ppi (zathura -> document );
200
+ zathura_document_t * document = zathura_get_document (zathura );
201
+ const double current_ppi = zathura_document_get_viewport_ppi (document );
201
202
if (fabs (ppi - current_ppi ) > DBL_EPSILON ) {
202
203
girara_debug ("monitor width: %d mm, pixels: %d, ppi: %0.2f" , width_mm , monitor_geom .width , ppi );
203
- zathura_document_set_viewport_ppi (zathura -> document , ppi );
204
+ zathura_document_set_viewport_ppi (document , ppi );
204
205
adjust_view (zathura );
205
206
render_all (zathura );
206
207
refresh_view (zathura );
@@ -803,12 +804,13 @@ static gboolean document_info_open(gpointer data) {
803
804
}
804
805
805
806
char * get_formatted_filename (zathura_t * zathura , bool statusbar ) {
806
- bool basename_only = false;
807
- const char * file_path = NULL ;
808
- if (zathura -> document != NULL ) {
809
- file_path = zathura_document_get_uri (zathura -> document );
807
+ bool basename_only = false;
808
+ const char * file_path = NULL ;
809
+ zathura_document_t * document = zathura_get_document (zathura );
810
+ if (document != NULL ) {
811
+ file_path = zathura_document_get_uri (document );
810
812
if (file_path == NULL ) {
811
- file_path = zathura_document_get_path (zathura -> document );
813
+ file_path = zathura_document_get_path (document );
812
814
}
813
815
}
814
816
if (statusbar == true) {
@@ -843,7 +845,7 @@ char* get_formatted_filename(zathura_t* zathura, bool statusbar) {
843
845
return g_strdup (file_path );
844
846
}
845
847
} else {
846
- const char * basename = zathura_document_get_basename (zathura -> document );
848
+ const char * basename = zathura_document_get_basename (document );
847
849
return g_strdup (basename );
848
850
}
849
851
}
@@ -1101,9 +1103,9 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
1101
1103
GtkAdjustment * vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (zathura - > ui .session - > gtk .view ));
1102
1104
1103
1105
const unsigned int view_width = floor (gtk_adjustment_get_page_size (hadjustment ));
1104
- zathura_document_set_viewport_width (zathura - > document , view_width );
1106
+ zathura_document_set_viewport_width (document , view_width );
1105
1107
const unsigned int view_height = floor (gtk_adjustment_get_page_size (vadjustment ));
1106
- zathura_document_set_viewport_height (zathura - > document , view_height );
1108
+ zathura_document_set_viewport_height (document , view_height );
1107
1109
1108
1110
zathura_update_view_ppi (zathura );
1109
1111
@@ -1112,7 +1114,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
1112
1114
1113
1115
/* get initial device scale */
1114
1116
const int device_factor = gtk_widget_get_scale_factor (zathura - > ui .session - > gtk .view );
1115
- zathura_document_set_device_factors (zathura - > document , device_factor , device_factor );
1117
+ zathura_document_set_device_factors (document , device_factor , device_factor );
1116
1118
1117
1119
/* create blank pages */
1118
1120
zathura -> pages = calloc (number_of_pages , sizeof (GtkWidget * ));
@@ -1182,7 +1184,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
1182
1184
page_right_to_left = file_info .page_right_to_left ;
1183
1185
1184
1186
page_widget_set_mode (zathura , page_padding , pages_per_row , first_page_column , page_right_to_left );
1185
- zathura_document_set_page_layout (zathura - > document , page_padding , pages_per_row , first_page_column );
1187
+ zathura_document_set_page_layout (document , page_padding , pages_per_row , first_page_column );
1186
1188
1187
1189
girara_set_view (zathura - > ui .session , zathura - > ui .page_widget );
1188
1190
@@ -1320,14 +1322,14 @@ void document_open_idle(zathura_t* zathura, const char* path, const char* passwo
1320
1322
}
1321
1323
1322
1324
bool document_save (zathura_t * zathura , const char * path , bool overwrite ) {
1323
- g_return_val_if_fail (zathura , false );
1324
- g_return_val_if_fail (zathura -> document , false);
1325
+ zathura_document_t * document = zathura_get_document (zathura );
1326
+ g_return_val_if_fail (document , false);
1325
1327
g_return_val_if_fail (path , false);
1326
1328
1327
1329
gchar * file_path = girara_fix_path (path );
1328
1330
/* use current basename if path points to a directory */
1329
1331
if (g_file_test (file_path , G_FILE_TEST_IS_DIR ) == TRUE) {
1330
- char * basename = g_path_get_basename (zathura_document_get_path (zathura -> document ));
1332
+ char * basename = g_path_get_basename (zathura_document_get_path (document ));
1331
1333
char * tmp = file_path ;
1332
1334
file_path = g_build_filename (file_path , basename , NULL );
1333
1335
g_free (tmp );
@@ -1341,7 +1343,7 @@ bool document_save(zathura_t* zathura, const char* path, bool overwrite) {
1341
1343
return false;
1342
1344
}
1343
1345
1344
- const zathura_error_t error = zathura_document_save_as (zathura -> document , file_path );
1346
+ const zathura_error_t error = zathura_document_save_as (document , file_path );
1345
1347
g_free (file_path );
1346
1348
1347
1349
if (error != ZATHURA_ERROR_OK ) {
@@ -1380,16 +1382,17 @@ static zathura_fileinfo_t zathura_get_document_fileinfo(zathura_t* zathura, zath
1380
1382
}
1381
1383
1382
1384
zathura_fileinfo_t zathura_get_fileinfo (zathura_t * zathura ) {
1383
- return zathura_get_document_fileinfo (zathura , zathura -> document );
1385
+ return zathura_get_document_fileinfo (zathura , zathura_get_document ( zathura ) );
1384
1386
}
1385
1387
1386
1388
zathura_fileinfo_t zathura_get_prefileinfo (zathura_t * zathura ) {
1387
1389
return zathura_get_document_fileinfo (zathura , zathura -> predecessor_document );
1388
1390
}
1389
1391
1390
1392
static void save_fileinfo_to_db (zathura_t * zathura ) {
1391
- const char * path = zathura_document_get_path (zathura -> document );
1392
- const uint8_t * file_hash = zathura_document_get_hash (zathura -> document );
1393
+ zathura_document_t * document = zathura_get_document (zathura );
1394
+ const char * path = zathura_document_get_path (document );
1395
+ const uint8_t * file_hash = zathura_document_get_hash (document );
1393
1396
1394
1397
zathura_fileinfo_t file_info = zathura_get_fileinfo (zathura );
1395
1398
@@ -1427,7 +1430,7 @@ bool document_predecessor_free(zathura_t* zathura) {
1427
1430
}
1428
1431
1429
1432
bool document_close (zathura_t * zathura , bool keep_monitor ) {
1430
- if (zathura == NULL || zathura -> document == NULL ) {
1433
+ if (zathura_has_document ( zathura ) ) {
1431
1434
return false;
1432
1435
}
1433
1436
@@ -1475,11 +1478,12 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
1475
1478
g_clear_object (& zathura -> sync .render_thread );
1476
1479
1477
1480
/* keep the current state to prevent flicker? */
1478
- bool override_predecessor = keep_monitor ;
1481
+ bool override_predecessor = keep_monitor ;
1482
+ zathura_document_t * document = zathura_get_document (zathura );
1479
1483
1480
1484
if (override_predecessor ) {
1481
1485
/* do not override predecessor buffer with empty pages */
1482
- unsigned int cur_page_num = zathura_document_get_current_page_number (zathura -> document );
1486
+ unsigned int cur_page_num = zathura_document_get_current_page_number (document );
1483
1487
ZathuraPage * cur_page = ZATHURA_PAGE (zathura -> pages [cur_page_num ]);
1484
1488
if (!zathura_page_widget_have_surface (cur_page )) {
1485
1489
override_predecessor = false;
@@ -1503,7 +1507,7 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
1503
1507
gtk_container_foreach (GTK_CONTAINER (zathura -> ui .page_widget ), remove_page_from_table , NULL );
1504
1508
1505
1509
if (!override_predecessor ) {
1506
- for (unsigned int i = 0 ; i < zathura_document_get_number_of_pages (zathura -> document ); i ++ ) {
1510
+ for (unsigned int i = 0 ; i < zathura_document_get_number_of_pages (document ); i ++ ) {
1507
1511
g_object_unref (zathura -> pages [i ]);
1508
1512
}
1509
1513
free (zathura -> pages );
@@ -1547,16 +1551,17 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
1547
1551
}
1548
1552
1549
1553
bool page_set (zathura_t * zathura , unsigned int page_id ) {
1550
- if (zathura == NULL || zathura -> document == NULL ) {
1554
+ if (zathura_has_document ( zathura ) == false ) {
1551
1555
goto error_out ;
1552
1556
}
1553
1557
1554
- zathura_page_t * page = zathura_document_get_page (zathura -> document , page_id );
1558
+ zathura_document_t * document = zathura_get_document (zathura );
1559
+ zathura_page_t * page = zathura_document_get_page (document , page_id );
1555
1560
if (page == NULL ) {
1556
1561
goto error_out ;
1557
1562
}
1558
1563
1559
- zathura_document_set_current_page_number (zathura -> document , page_id );
1564
+ zathura_document_set_current_page_number (document , page_id );
1560
1565
1561
1566
bool continuous_hist_save = false;
1562
1567
girara_setting_get (zathura -> ui .session , "continuous-hist-save" , & continuous_hist_save );
@@ -1576,12 +1581,13 @@ void statusbar_page_number_update(zathura_t* zathura) {
1576
1581
return ;
1577
1582
}
1578
1583
1579
- unsigned int number_of_pages = zathura_document_get_number_of_pages (zathura -> document );
1580
- unsigned int current_page_number = zathura_document_get_current_page_number (zathura -> document );
1581
- unsigned int page_number_percent = number_of_pages ? 100 * (current_page_number + 1 ) / number_of_pages : 0 ;
1584
+ zathura_document_t * document = zathura_get_document (zathura );
1585
+ if (document != NULL ) {
1586
+ unsigned int number_of_pages = zathura_document_get_number_of_pages (document );
1587
+ unsigned int current_page_number = zathura_document_get_current_page_number (document );
1588
+ unsigned int page_number_percent = number_of_pages ? 100 * (current_page_number + 1 ) / number_of_pages : 0 ;
1582
1589
1583
- if (zathura -> document != NULL ) {
1584
- zathura_page_t * page = zathura_document_get_page (zathura -> document , current_page_number );
1590
+ zathura_page_t * page = zathura_document_get_page (document , current_page_number );
1585
1591
const char * page_label = zathura_page_get_label (page , NULL );
1586
1592
1587
1593
bool show_percent = false;
@@ -1624,6 +1630,11 @@ void statusbar_page_number_update(zathura_t* zathura) {
1624
1630
1625
1631
void page_widget_set_mode (zathura_t * zathura , unsigned int page_padding , unsigned int pages_per_row ,
1626
1632
unsigned int first_page_column , bool page_right_to_left ) {
1633
+ zathura_document_t * document = zathura_get_document (zathura );
1634
+ if (document == NULL ) {
1635
+ return ;
1636
+ }
1637
+
1627
1638
/* show at least one page */
1628
1639
if (pages_per_row == 0 ) {
1629
1640
pages_per_row = 1 ;
@@ -1637,13 +1648,9 @@ void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigne
1637
1648
first_page_column = ((first_page_column - 1 ) % pages_per_row ) + 1 ;
1638
1649
}
1639
1650
1640
- if (zathura -> document == NULL ) {
1641
- return ;
1642
- }
1643
-
1644
1651
gtk_container_foreach (GTK_CONTAINER (zathura -> ui .page_widget ), remove_page_from_table , NULL );
1645
1652
1646
- unsigned int number_of_pages = zathura_document_get_number_of_pages (zathura -> document );
1653
+ unsigned int number_of_pages = zathura_document_get_number_of_pages (document );
1647
1654
1648
1655
gtk_grid_set_row_spacing (GTK_GRID (zathura -> ui .page_widget ), page_padding );
1649
1656
gtk_grid_set_column_spacing (GTK_GRID (zathura -> ui .page_widget ), page_padding );
@@ -1664,27 +1671,28 @@ void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigne
1664
1671
}
1665
1672
1666
1673
bool position_set (zathura_t * zathura , double position_x , double position_y ) {
1667
- if (zathura == NULL || zathura -> document == NULL ) {
1674
+ zathura_document_t * document = zathura_get_document (zathura );
1675
+ if (document == NULL ) {
1668
1676
return false;
1669
1677
}
1670
1678
1671
1679
double comppos_x , comppos_y ;
1672
- const unsigned int page_id = zathura_document_get_current_page_number (zathura -> document );
1680
+ const unsigned int page_id = zathura_document_get_current_page_number (document );
1673
1681
1674
1682
bool vertical_center = false;
1675
1683
girara_setting_get (zathura -> ui .session , "vertical-center" , & vertical_center );
1676
1684
1677
1685
/* xalign = 0.5: center horizontally (with the page, not the document) */
1678
1686
if (vertical_center == true) {
1679
1687
/* yalign = 0.5: center vertically */
1680
- page_number_to_position (zathura -> document , page_id , 0.5 , 0.5 , & comppos_x , & comppos_y );
1688
+ page_number_to_position (document , page_id , 0.5 , 0.5 , & comppos_x , & comppos_y );
1681
1689
} else {
1682
1690
/* yalign = 0.0: align page and viewport edges at the top */
1683
- page_number_to_position (zathura -> document , page_id , 0.5 , 0.0 , & comppos_x , & comppos_y );
1691
+ page_number_to_position (document , page_id , 0.5 , 0.0 , & comppos_x , & comppos_y );
1684
1692
}
1685
1693
1686
1694
/* automatic horizontal adjustment */
1687
- zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode (zathura -> document );
1695
+ zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode (document );
1688
1696
1689
1697
/* negative position_x mean: use the computed value */
1690
1698
if (position_x < 0 ) {
@@ -1703,8 +1711,8 @@ bool position_set(zathura_t* zathura, double position_x, double position_y) {
1703
1711
}
1704
1712
1705
1713
/* set the position */
1706
- zathura_document_set_position_x (zathura -> document , position_x );
1707
- zathura_document_set_position_y (zathura -> document , position_y );
1714
+ zathura_document_set_position_x (document , position_x );
1715
+ zathura_document_set_position_y (document , position_y );
1708
1716
1709
1717
/* trigger a 'change' event for both adjustments */
1710
1718
refresh_view (zathura );
@@ -1721,12 +1729,12 @@ void refresh_view(zathura_t* zathura) {
1721
1729
1722
1730
bool adjust_view (zathura_t * zathura ) {
1723
1731
g_return_val_if_fail (zathura != NULL , false);
1724
-
1725
- if (zathura -> ui .page_widget == NULL || zathura -> document == NULL ) {
1732
+ zathura_document_t * document = zathura_get_document ( zathura );
1733
+ if (zathura -> ui .page_widget == NULL || document == NULL ) {
1726
1734
goto error_ret ;
1727
1735
}
1728
1736
1729
- zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode (zathura -> document );
1737
+ zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode (document );
1730
1738
if (adjust_mode == ZATHURA_ADJUST_NONE ) {
1731
1739
/* there is nothing todo */
1732
1740
goto error_ret ;
@@ -1736,17 +1744,17 @@ bool adjust_view(zathura_t* zathura) {
1736
1744
unsigned int document_height = 0 , document_width = 0 ;
1737
1745
unsigned int view_height = 0 , view_width = 0 ;
1738
1746
1739
- zathura_document_get_cell_size (zathura -> document , & cell_height , & cell_width );
1740
- zathura_document_get_document_size (zathura -> document , & document_height , & document_width );
1741
- zathura_document_get_viewport_size (zathura -> document , & view_height , & view_width );
1747
+ zathura_document_get_cell_size (document , & cell_height , & cell_width );
1748
+ zathura_document_get_document_size (document , & document_height , & document_width );
1749
+ zathura_document_get_viewport_size (document , & view_height , & view_width );
1742
1750
1743
1751
if (view_height == 0 || view_width == 0 || cell_height == 0 || cell_width == 0 || document_width == 0 ) {
1744
1752
goto error_ret ;
1745
1753
}
1746
1754
1747
1755
double page_ratio = (double )cell_height / (double )document_width ;
1748
1756
double view_ratio = (double )view_height / (double )view_width ;
1749
- double zoom = zathura_document_get_zoom (zathura -> document );
1757
+ double zoom = zathura_document_get_zoom (document );
1750
1758
double newzoom = zoom ;
1751
1759
1752
1760
if (adjust_mode == ZATHURA_ADJUST_WIDTH || (adjust_mode == ZATHURA_ADJUST_BESTFIT && page_ratio < view_ratio )) {
@@ -1758,9 +1766,9 @@ bool adjust_view(zathura_t* zathura) {
1758
1766
}
1759
1767
1760
1768
/* save new zoom and recompute cell size */
1761
- zathura_document_set_zoom (zathura -> document , newzoom );
1769
+ zathura_document_set_zoom (document , newzoom );
1762
1770
unsigned int new_cell_height = 0 , new_cell_width = 0 ;
1763
- zathura_document_get_cell_size (zathura -> document , & new_cell_height , & new_cell_width );
1771
+ zathura_document_get_cell_size (document , & new_cell_height , & new_cell_width );
1764
1772
1765
1773
/*
1766
1774
* XXX requiring a larger difference apparently circumvents #94 for some users; this is not a
@@ -1774,7 +1782,7 @@ bool adjust_view(zathura_t* zathura) {
1774
1782
refresh_view (zathura );
1775
1783
} else {
1776
1784
/* otherwise set the old zoom and leave */
1777
- zathura_document_set_zoom (zathura -> document , zoom );
1785
+ zathura_document_set_zoom (document , zoom );
1778
1786
}
1779
1787
1780
1788
error_ret :
@@ -1793,15 +1801,16 @@ static gboolean zathura_signal_sigterm(gpointer data) {
1793
1801
#endif
1794
1802
1795
1803
void zathura_show_signature_information (zathura_t * zathura , bool show ) {
1796
- if (zathura -> document == NULL ) {
1804
+ zathura_document_t * document = zathura_get_document (zathura );
1805
+ if (document == NULL ) {
1797
1806
return ;
1798
1807
}
1799
1808
1800
1809
GValue show_sig_info_value = {0 };
1801
1810
g_value_init (& show_sig_info_value , G_TYPE_BOOLEAN );
1802
1811
g_value_set_boolean (& show_sig_info_value , show );
1803
1812
1804
- const unsigned int number_of_pages = zathura_document_get_number_of_pages (zathura -> document );
1813
+ const unsigned int number_of_pages = zathura_document_get_number_of_pages (document );
1805
1814
for (unsigned int page = 0 ; page != number_of_pages ; ++ page ) {
1806
1815
// draw signature info
1807
1816
g_object_set_property (G_OBJECT (zathura -> pages [page ]), "draw-signatures" , & show_sig_info_value );
0 commit comments