# SDK Pullenti Unitext, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved.
# Non-Commercial Freeware and Commercial Software.
# This class is generated using the converter UniSharping (www.unisharping.ru) from Pullenti C# project.
# The latest version of the code is available on the site www.pullenti.ru

from pullenti.unisharp.Streams import Stream

from pullenti.unitext.internal.pdf.PdfObject import PdfObject

class PdfName(PdfObject):
    
    def __init__(self) -> None:
        super().__init__()
        self.name = None;
    
    def to_string_ex(self, lev : int) -> str:
        return self.name
    
    def is_simple(self, lev : int) -> bool:
        return True
    
    def write0_(self, s : Stream) -> None:
        s.writebyte(ord('/'))
        for ch in self.name: 
            if ("%()<>[]{}/#".find(ch) >= 0 or (ord(ch)) <= 0x20): 
                hex0_ = "{:02X}".format(ord(ch))
                s.writebyte(ord('#'))
                s.writebyte(ord(hex0_[0]))
                s.writebyte(ord(hex0_[1]))
            else: 
                s.writebyte(ord(ch))
    
    @staticmethod
    def _new228(_arg1 : str) -> 'PdfName':
        res = PdfName()
        res.name = _arg1
        return res