Skip to content

Commit

Permalink
Small API cleanings
Browse files Browse the repository at this point in the history
- PdfTextBox/PdChoiceField: Fixed Spellchecking casing to SpellChecking
- Some more classes made final
- PdfColorSpaceInitializer: Make Take() private

Also updated TODO after second pass API check
  • Loading branch information
ceztko committed Oct 27, 2024
1 parent af7dc59 commit 8492230
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 52 deletions.
1 change: 1 addition & 0 deletions API-MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 0.10.1 -> 1.0.0
- `PdfTextBox`/`PdChoiceField`: Fixed `Spellchecking` casing to `SpellChecking`
- `PdfDrawTextMultiLineParams`:
* Inverted semantics of `Clip` and renamed to `SkipClip`
* Inverted semantics of `SkipSpaces` and renamed to `PreserveTrailingSpaces`
Expand Down
21 changes: 17 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
- PdfPage: Add a method to retrieve rotation in radians
- Settle TryGetSubstituteFont
- Restore PdfShadingPattern, PdfTilingPattern
- Check PdfExtension API
- Check performances of PdfContentStreamReader
- Evaluate make private PdfFontManager::EmbedFonts
- Make PdfDocument constructor private
- PdfOperatorUtils: Move to aux/PdfConver.h most functions
- PdfTokenizer: Evaluate making private IsWhitespace, IsDelimiter,
IsTokenDelimiter, IsRegular, IsPrintable


### After 1.0
- PdfVariant/PdfObject: Evaluate adding a TryGetStringLenient(string_view& str)
that catches both PdfString/PdfName
- Add remaining PdfNameTree(s) (also stub)
- Add remaining PdfContentStreamOperators
- According to 5014.CIDFont_Spec page 71-72-73 begincidchar, begincidrange,
beginbfchar, beginbfrange have a limit of 100 entries. Fix it where relevant
- noexcept nullable<T> methods
- nullable<T&>: Accept T* as well?. Disable nullable<T*>
- Check/Review doxygen doc
- If the doc is updated, then should not allow to set an encryption
- If the doc is updated and has an encryption, it should not allow to remove it
Expand All @@ -33,8 +46,6 @@
- PdfParserObject: Evaluate release the device after loading
- Review all page import functions to check correct working/improve the code
- PdfElement: Optimize, keep dictionary/array pointer. Evaluate Add shared_ptr PdfElement::GetObjectPtr()
- Implement full text extraction, including search in predefined
CMap(s) as described in Pdf Reference and here https://stackoverflow.com/a/26910569/213871
- Check what do with tools/restore manuals
- Fix/complete handling of text extraction in rotated pages (??? Done?)
- Add method to retrieve shared_ptr from PdfObject, PdfFont (and
Expand All @@ -47,7 +58,7 @@
- PdfParser: Handle invalid startxref by rebuilding the index,
similarly to what pdf.js does
- Review PdfPageCollection::AppendDocumentPages(),
PdfPageCollection::InsertDocumentPageAt(), PdfPage::MoveAt() code
PdfPageCollection::InsertDocumentPageAt() code
- Add text shaping with Harfbuzz https://github.com/harfbuzz/harfbuzz
- Add fail safe sign/update mechanism, meaning the stream gets trimmed
to initial length if there's a crash. Not so easy, especially since
Expand All @@ -56,9 +67,11 @@
- PdfDifferenceEncoding: Rework Adobe Glyph List handling and moving it to private folder
- Option to unfold Unicode ligatures to separate codepoints during encoded -> utf8 conversion
- Option to convert Unicode ligatures <-> separate codepoints when drawing strings/converting to encoded
- Optimize charbuff to not initialize memory, keeping std::string compatibility
- Optimize charbuff to not initialize memory, keeping std::string compatibility,
see https://en.cppreference.com/w/cpp/string/basic_string/resize_and_overwrite
- Add backtrace: https://github.com/boostorg/stacktrace

### Ideas:
- PdfFontManager: Consider also statically caching the queries and filepaths.
Maybe we could also weakly (weak shared pointer) cache metrics instead of fonts
- PdfName: Evaluate unescape lazily, or offer a way to debug/inspect the unescaped sequence a posteriori
8 changes: 4 additions & 4 deletions src/podofo/main/PdfButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ PdfButton::PdfButton(PdfObject& obj, PdfAcroForm* acroform, PdfFieldType fieldTy

bool PdfButton::IsPushButton() const
{
return this->GetFieldFlag(static_cast<int>(ePdfButton_PushButton), false);
return this->GetFieldFlag(static_cast<int>(PdfButton_PushButton), false);
}

bool PdfButton::IsCheckBox() const
{
return (!this->GetFieldFlag(static_cast<int>(ePdfButton_Radio), false) &&
!this->GetFieldFlag(static_cast<int>(ePdfButton_PushButton), false));
return (!this->GetFieldFlag(static_cast<int>(PdfButton_Radio), false) &&
!this->GetFieldFlag(static_cast<int>(PdfButton_PushButton), false));
}

bool PdfButton::IsRadioButton() const
{
return this->GetFieldFlag(static_cast<int>(ePdfButton_Radio), false);
return this->GetFieldFlag(static_cast<int>(PdfButton_Radio), false);
}

void PdfButton::SetCaption(nullable<const PdfString&> text)
Expand Down
22 changes: 11 additions & 11 deletions src/podofo/main/PdfChoiceField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,45 +174,45 @@ int PdChoiceField::GetSelectedIndex() const

bool PdChoiceField::IsComboBox() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_Combo), false);
return this->GetFieldFlag(static_cast<int>(PdfListField_Combo), false);
}

void PdChoiceField::SetSpellcheckingEnabled(bool spellCheck)
void PdChoiceField::SetSpellCheckingEnabled(bool spellCheck)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_NoSpellcheck), !spellCheck);
this->SetFieldFlag(static_cast<int>(PdfListField_NoSpellcheck), !spellCheck);
}

bool PdChoiceField::IsSpellcheckingEnabled() const
bool PdChoiceField::IsSpellCheckingEnabled() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_NoSpellcheck), true);
return this->GetFieldFlag(static_cast<int>(PdfListField_NoSpellcheck), true);
}

void PdChoiceField::SetSorted(bool sorted)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Sort), sorted);
this->SetFieldFlag(static_cast<int>(PdfListField_Sort), sorted);
}

bool PdChoiceField::IsSorted() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_Sort), false);
return this->GetFieldFlag(static_cast<int>(PdfListField_Sort), false);
}

void PdChoiceField::SetMultiSelect(bool multi)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_MultiSelect), multi);
this->SetFieldFlag(static_cast<int>(PdfListField_MultiSelect), multi);
}

bool PdChoiceField::IsMultiSelect() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_MultiSelect), false);
return this->GetFieldFlag(static_cast<int>(PdfListField_MultiSelect), false);
}

void PdChoiceField::SetCommitOnSelectionChange(bool commit)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_CommitOnSelChange), commit);
this->SetFieldFlag(static_cast<int>(PdfListField_CommitOnSelChange), commit);
}

bool PdChoiceField::IsCommitOnSelectionChange() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_CommitOnSelChange), false);
return this->GetFieldFlag(static_cast<int>(PdfListField_CommitOnSelChange), false);
}
4 changes: 2 additions & 2 deletions src/podofo/main/PdfChoiceField.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ namespace PoDoFo
*
* combobox are spellchecked by default
*/
void SetSpellcheckingEnabled(bool spellCheck);
void SetSpellCheckingEnabled(bool spellCheck);

/**
* \returns true if spellchecking is enabled for this combobox
*/
bool IsSpellcheckingEnabled() const;
bool IsSpellCheckingEnabled() const;

/**
* Enable or disable sorting of items.
Expand Down
7 changes: 5 additions & 2 deletions src/podofo/main/PdfColorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class PODOFO_API PdfColorSpace final : public PdfDictionaryElement
*/
class PODOFO_API PdfColorSpaceInitializer final
{
friend class PdfGraphicsStateWrapper;

PODOFO_STACK_ONLY

public:
Expand All @@ -56,15 +58,16 @@ class PODOFO_API PdfColorSpaceInitializer final

bool IsNull() const;

PdfColorSpaceFilterPtr Take(const PdfColorSpace*& element);

PdfColorSpaceInitializer(const PdfColorSpaceInitializer&) = default;
PdfColorSpaceInitializer& operator=(const PdfColorSpaceInitializer&) = default;

public:
const PdfColorSpaceFilter& GetFilter() const { return *m_Filter; }
PdfColorSpaceFilterPtr GetFilterPtr() const { return m_Filter; }

private:
PdfColorSpaceFilterPtr Take(const PdfColorSpace*& element);

private:
PdfColorSpaceFilterPtr m_Filter;
const PdfColorSpace* m_Element;
Expand Down
8 changes: 4 additions & 4 deletions src/podofo/main/PdfComboBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ using namespace PoDoFo;
PdfComboBox::PdfComboBox(PdfAcroForm& acroform, const shared_ptr<PdfField>& parent)
: PdChoiceField(acroform, PdfFieldType::ComboBox, parent)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Combo), true);
this->SetFieldFlag(static_cast<int>(PdfListField_Combo), true);
}

PdfComboBox::PdfComboBox(PdfAnnotationWidget& widget, const shared_ptr<PdfField>& parent)
: PdChoiceField(widget, PdfFieldType::ComboBox, parent)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Combo), true);
this->SetFieldFlag(static_cast<int>(PdfListField_Combo), true);
}

PdfComboBox::PdfComboBox(PdfObject& obj, PdfAcroForm* acroform)
Expand All @@ -31,12 +31,12 @@ PdfComboBox::PdfComboBox(PdfObject& obj, PdfAcroForm* acroform)

void PdfComboBox::SetEditable(bool edit)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Edit), edit);
this->SetFieldFlag(static_cast<int>(PdfListField_Edit), edit);
}

bool PdfComboBox::IsEditable() const
{
return this->GetFieldFlag(static_cast<int>(ePdfListField_Edit), false);
return this->GetFieldFlag(static_cast<int>(PdfListField_Edit), false);
}

PdfComboBox* PdfComboBox::GetParent()
Expand Down
2 changes: 1 addition & 1 deletion src/podofo/main/PdfDifferenceEncoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PdfFontMetrics;
/** A helper class for PdfDifferenceEncoding that
* can be used to create a differences array.
*/
class PODOFO_API PdfDifferenceList
class PODOFO_API PdfDifferenceList final
{
struct Difference
{
Expand Down
12 changes: 6 additions & 6 deletions src/podofo/main/PdfField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,9 @@ PdfFieldType PdfField::getFieldType(const PdfObject& obj)
int64_t flags;
PdfField::GetFieldFlags(obj, flags);

if ((flags & PdfButton::ePdfButton_PushButton) == PdfButton::ePdfButton_PushButton)
if ((flags & PdfButton::PdfButton_PushButton) == PdfButton::PdfButton_PushButton)
ret = PdfFieldType::PushButton;
else if ((flags & PdfButton::ePdfButton_Radio) == PdfButton::ePdfButton_Radio)
else if ((flags & PdfButton::PdfButton_Radio) == PdfButton::PdfButton_Radio)
ret = PdfFieldType::RadioButton;
else
ret = PdfFieldType::CheckBox;
Expand All @@ -412,7 +412,7 @@ PdfFieldType PdfField::getFieldType(const PdfObject& obj)
int64_t flags;
PdfField::GetFieldFlags(obj, flags);

if ((flags & PdChoiceField::ePdfListField_Combo) == PdChoiceField::ePdfListField_Combo)
if ((flags & PdChoiceField::PdfListField_Combo) == PdChoiceField::PdfListField_Combo)
ret = PdfFieldType::ComboBox;
else
ret = PdfFieldType::ListBox;
Expand All @@ -435,11 +435,11 @@ void PdfField::init()
break;
case PdfFieldType::PushButton:
dict.AddKey("FT"_n, "Btn"_n);
dict.AddKey("Ff"_n, (int64_t)PdfButton::ePdfButton_PushButton);
dict.AddKey("Ff"_n, (int64_t)PdfButton::PdfButton_PushButton);
break;
case PdfFieldType::RadioButton:
dict.AddKey("FT"_n, "Btn"_n);
dict.AddKey("Ff"_n, (int64_t)(PdfButton::ePdfButton_Radio | PdfButton::ePdfButton_NoToggleOff));
dict.AddKey("Ff"_n, (int64_t)(PdfButton::PdfButton_Radio | PdfButton::PdfButton_NoToggleOff));
break;
case PdfFieldType::TextBox:
dict.AddKey("FT"_n, "Tx"_n);
Expand All @@ -449,7 +449,7 @@ void PdfField::init()
break;
case PdfFieldType::ComboBox:
dict.AddKey("FT"_n, "Ch"_n);
dict.AddKey("Ff"_n, (int64_t)PdChoiceField::ePdfListField_Combo);
dict.AddKey("Ff"_n, (int64_t)PdChoiceField::PdfListField_Combo);
break;
case PdfFieldType::Signature:
dict.AddKey("FT"_n, "Sig"_n);
Expand Down
20 changes: 10 additions & 10 deletions src/podofo/main/PdfField.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class PODOFO_API PdfField : public PdfDictionaryElement
protected:
enum
{
ePdfButton_NoToggleOff = 0x0004000,
ePdfButton_Radio = 0x0008000,
ePdfButton_PushButton = 0x0010000,
ePdfButton_RadioInUnison = 0x2000000,
ePdfListField_Combo = 0x0020000,
ePdfListField_Edit = 0x0040000,
ePdfListField_Sort = 0x0080000,
ePdfListField_MultiSelect = 0x0200000,
ePdfListField_NoSpellcheck = 0x0400000,
ePdfListField_CommitOnSelChange = 0x4000000
PdfButton_NoToggleOff = 0x0004000,
PdfButton_Radio = 0x0008000,
PdfButton_PushButton = 0x0010000,
PdfButton_RadioInUnison = 0x2000000,
PdfListField_Combo = 0x0020000,
PdfListField_Edit = 0x0040000,
PdfListField_Sort = 0x0080000,
PdfListField_MultiSelect = 0x0200000,
PdfListField_NoSpellcheck = 0x0400000,
PdfListField_CommitOnSelChange = 0x4000000
};

private:
Expand Down
4 changes: 2 additions & 2 deletions src/podofo/main/PdfListBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ using namespace PoDoFo;
PdfListBox::PdfListBox(PdfAcroForm& acroform, const shared_ptr<PdfField>& parent)
: PdChoiceField(acroform, PdfFieldType::ListBox, parent)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Combo), false);
this->SetFieldFlag(static_cast<int>(PdfListField_Combo), false);
}

PdfListBox::PdfListBox(PdfAnnotationWidget& widget, const shared_ptr<PdfField>& parent)
: PdChoiceField(widget, PdfFieldType::ListBox, parent)
{
this->SetFieldFlag(static_cast<int>(ePdfListField_Combo), false);
this->SetFieldFlag(static_cast<int>(PdfListField_Combo), false);
}

PdfListBox::PdfListBox(PdfObject& obj, PdfAcroForm* acroform)
Expand Down
1 change: 1 addition & 0 deletions src/podofo/main/PdfNameTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class PdfNameTree final : public PdfNameTreeBase
}
};

// TODO: Add more trees
using PdfDestinations = PdfNameTree<PdfDestination>;
using PdfEmbeddedFiles = PdfNameTree<PdfFileSpec>;

Expand Down
2 changes: 1 addition & 1 deletion src/podofo/main/PdfPushButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ PdfPushButton::PdfPushButton(PdfObject& obj, PdfAcroForm* acroform)
void PdfPushButton::init()
{
// make a push button
this->SetFieldFlag(static_cast<int>(ePdfButton_PushButton), true);
this->SetFieldFlag(static_cast<int>(PdfButton_PushButton), true);
}

void PdfPushButton::SetRolloverCaption(nullable<const PdfString&> text)
Expand Down
4 changes: 2 additions & 2 deletions src/podofo/main/PdfTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ bool PdfTextBox::IsFileField() const
return this->GetFieldFlag(static_cast<int>(PdfTextBox_FileSelect), false);
}

void PdfTextBox::SetSpellcheckingEnabled(bool spellcheck)
void PdfTextBox::SetSpellCheckingEnabled(bool spellcheck)
{
this->SetFieldFlag(static_cast<int>(PdfTextBox_NoSpellcheck), !spellcheck);
}

bool PdfTextBox::IsSpellcheckingEnabled() const
bool PdfTextBox::IsSpellCheckingEnabled() const
{
return this->GetFieldFlag(static_cast<int>(PdfTextBox_NoSpellcheck), true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/podofo/main/PdfTextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ namespace PoDoFo
*
* Text fields are spellchecked by default
*/
void SetSpellcheckingEnabled(bool spellcheck);
void SetSpellCheckingEnabled(bool spellcheck);

/**
* \returns true if spellchecking is enabled for this text field
*/
bool IsSpellcheckingEnabled() const;
bool IsSpellCheckingEnabled() const;

/**
* Enable/disable scrollbars for this text field
Expand Down
2 changes: 1 addition & 1 deletion src/podofo/main/PdfXMPMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace PoDoFo
{
struct PODOFO_API PdfXMPMetadata
struct PODOFO_API PdfXMPMetadata final
{
PdfXMPMetadata();
nullable<PdfString> Title;
Expand Down

0 comments on commit 8492230

Please sign in to comment.