Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add blob.length property #225

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/uharfbuzz/_harfbuzz.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,12 @@ cdef class Buffer:

cdef class Blob:
cdef hb_blob_t* _hb_blob
cdef object _data

def __cinit__(self, bytes data = None):
if data is not None:
self._data = data
self._hb_blob = hb_blob_create(
data, len(data), HB_MEMORY_MODE_READONLY, NULL, NULL)
data, len(data), HB_MEMORY_MODE_DUPLICATE, NULL, NULL)
else:
self._data = bytes()
self._hb_blob = hb_blob_get_empty()

@staticmethod
Expand All @@ -400,9 +397,6 @@ cdef class Blob:

cdef Blob wrapper = Blob.__new__(Blob)
wrapper._hb_blob = hb_blob
cdef unsigned int blob_length
cdef const_char* blob_data = hb_blob_get_data(hb_blob, &blob_length)
wrapper._data = blob_data[:blob_length]
return wrapper

@classmethod
Expand All @@ -417,17 +411,19 @@ cdef class Blob:

def __dealloc__(self):
hb_blob_destroy(self._hb_blob)
self._data = None

def __len__(self) -> int:
return len(self._data)
return hb_blob_get_length(self._hb_blob)

def __bool__(self) -> bool:
return bool(self._data)
return len(self) > 0

@property
def data(self) -> bytes:
return self._data
"""Return the blob's data as bytes."""
cdef unsigned int blob_length
cdef const_char* blob_data = hb_blob_get_data(self._hb_blob, &blob_length)
return blob_data[:blob_length]


class OTVarAxisFlags(IntFlag):
Expand Down
Loading