Class: PDFium::Bookmark
- Inherits:
-
Object
- Object
- PDFium::Bookmark
- Defined in:
- ext/pdfium_ext/bookmark.cc,
ext/pdfium_ext/bookmark.cc
Overview
Bookmarks on a Document form a tree structure. Each can have siblings and children
Instance Method Summary collapse
-
#children ⇒ BookmarkList
All Bookmarks that are children.
-
#destination ⇒ Hash
Returns the destination data of the bookmark.
-
#next_sibling ⇒ Bookmark
Returns the Bookmark that comes after this one.
-
#title ⇒ String encoded as UTF-16LE
Returns the title of the bookmark in UTF-16LE format.
Instance Method Details
#children ⇒ BookmarkList
All Bookmarks that are children. If the Bookmark has no children, an empty list is returned
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'ext/pdfium_ext/bookmark.cc', line 106
static VALUE
bookmark_children(VALUE self)
{
Bookmark *bm;
Data_Get_Struct(self, Bookmark, bm);
CPDF_BookmarkTree tree(bm->doc_wrapper->document);
CPDF_Bookmark child( tree.GetFirstChild(*bm->bookmark) );
VALUE args[1];
if (child.GetDict()){
args[0] = rb_hash_new();
rb_hash_aset(args[0], ID2SYM(rb_intern("parent")), self);
args[0] = rb_class_new_instance( 1, args, RB::Bookmark() );
} else {
args[0] = Qnil; //rb_class_new_instance( 1, args, T_NIL );
}
return rb_class_new_instance( 1, args, RB::BookmarkList() );
}
|
#destination ⇒ Hash
Returns the destination data of the bookmark. Only the destination type is tested. Bug reports and confirmation on the action type is appreciated.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'ext/pdfium_ext/bookmark.cc', line 177
static VALUE
bookmark_destination(VALUE self)
{
Bookmark *bm;
Data_Get_Struct(self, Bookmark, bm);
auto doc = bm->doc_wrapper->document;
VALUE hash=rb_hash_new();
CPDF_Dest dest = bm->bookmark->GetDest( doc );
if (dest){
rb_hash_aset(hash, ID2SYM( rb_intern("type") ), ID2SYM(rb_intern("destination")));
rb_hash_aset(hash, ID2SYM( rb_intern("page_number") ), INT2NUM(dest.GetPageIndex(doc)));
} else {
CPDF_Action action = bm->bookmark->GetAction();
if (action){
rb_hash_aset(hash, ID2SYM( rb_intern("type") ), ID2SYM(rb_intern("action")));
rb_hash_aset(hash, ID2SYM( rb_intern("action") ),
rb_str_new2( action.GetTypeName().c_str() ) );
rb_hash_aset(hash, ID2SYM( rb_intern("uri") ),
rb_str_new2( action.GetURI(doc).c_str() ) );
} else {
rb_hash_aset(hash, ID2SYM( rb_intern("type") ), ID2SYM(rb_intern("unknown")));
}
}
return hash;
}
|
#next_sibling ⇒ Bookmark
Returns the Bookmark that comes after this one
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'ext/pdfium_ext/bookmark.cc', line 134
static VALUE
bookmark_next_sibling(VALUE self)
{
Bookmark *bm;
Data_Get_Struct(self, Bookmark, bm);
CPDF_BookmarkTree tree(bm->doc_wrapper->document);
CPDF_Bookmark next = tree.GetNextSibling(*bm->bookmark);
if (next.GetDict()){
VALUE args[1];
args[0] = rb_hash_new();
rb_hash_aset(args[0], ID2SYM(rb_intern("sibling")), self);
return rb_class_new_instance( 1, args, RB::Bookmark() );
} else {
return Qnil;
}
}
|
#title ⇒ String encoded as UTF-16LE
Returns the title of the bookmark in UTF-16LE format. This means that the string cannot be directly compared to a ASCII string, and must be converted.
bookmark.title.encode!("ASCII-8BIT")
163 164 165 166 167 |
# File 'ext/pdfium_ext/bookmark.cc', line 163
static VALUE
bookmark_title(VALUE self)
{
return RB::to_string( RB2BM(self)->GetTitle() );
}
|