1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
//! Playdate text API
use core::ffi::{c_int, c_char};
use alloc::ffi::NulError;
use alloc::boxed::Box;
use fs::Path;
use sys::ffi::{CString, CStr, LCDFont, LCDFontGlyph, LCDFontPage, LCDBitmap};
use sys::traits::AsRaw;
pub use sys::ffi::PDStringEncoding as StringEncoding;
use crate::Graphics;
use crate::bitmap::BitmapRef;
use crate::error::{Error, ApiError};
/// Draws the given `text` using the provided coords `x`, `y`.
///
/// Encoding is always `StringEncoding::UTF8`.
/// If another encoding is desired, use [`draw_text_cstr`] instead.
///
/// If no `font` has been set with [`set_font`],
/// the default system font `Asheville Sans 14 Light` is used.
///
/// This function is shorthand for [`Graphics::draw_text`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::drawText`].
#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
#[inline(always)]
pub fn draw_text<S: AsRef<str>>(text: S, x: c_int, y: c_int) -> Result<c_int, NulError> {
Graphics::Default().draw_text(text, x, y)
}
/// Draws the given `text` using the provided options.
///
/// If no `font` has been set with [`set_font`],
/// the default system font `Asheville Sans 14 Light` is used.
///
/// Same as [`draw_text`] but takes a [`sys::ffi::CStr`],
/// but little bit more efficient.
///
/// This function is shorthand for [`Graphics::draw_text_cstr`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::drawText`].
#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
#[inline(always)]
pub fn draw_text_cstr(text: &CStr, encoding: StringEncoding, x: c_int, y: c_int) -> c_int {
Graphics::Default().draw_text_cstr(text, encoding, x, y)
}
/// Returns the width of the given `text` in the given `font`.
///
/// This function is shorthand for [`Graphics::get_text_width`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
#[inline(always)]
pub fn get_text_width<S: AsRef<str>>(text: S, font: Option<&Font>, tracking: c_int) -> Result<c_int, NulError> {
Graphics::Default().get_text_width(text, font, tracking)
}
/// Returns the width of the given `text` in the given `font`.
///
/// Same as [`get_text_width`] but takes a [`sys::ffi::CStr`],
/// but little bit more efficient.
///
/// This function is shorthand for [`Graphics::get_text_width_cstr`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
#[inline(always)]
pub fn get_text_width_cstr(text: &CStr, encoding: StringEncoding, font: Option<&Font>, tracking: c_int) -> c_int {
Graphics::Default().get_text_width_cstr(text, encoding, font, tracking)
}
/// Returns the height of the given `font`.
///
/// This function is shorthand for [`Graphics::get_font_height`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getFontHeight`].
#[doc(alias = "sys::ffi::playdate_graphics::getFontHeight")]
#[inline(always)]
pub fn get_font_height(font: &Font) -> u8 { Graphics::Default().get_font_height(font) }
/// Sets the `font` to use in subsequent [`draw_text`] calls.
///
/// This function is shorthand for [`Graphics::set_font`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setFont`].
#[doc(alias = "sys::ffi::playdate_graphics::setFont")]
#[inline(always)]
pub fn set_font(font: &Font) { Graphics::Default().set_font(font) }
/// Returns the kerning adjustment between characters `glyph_code` and `next_code` as specified by the font
///
/// This function is shorthand for [`Graphics::get_glyph_kerning`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getGlyphKerning`].
#[doc(alias = "sys::ffi::playdate_graphics::getGlyphKerning")]
#[inline(always)]
pub fn get_glyph_kerning(glyph: &Glyph, glyph_code: u32, next_code: u32) -> c_int {
Graphics::Default().get_glyph_kerning(glyph, glyph_code, next_code)
}
/// Returns an [`Glyph`] object for character `c` in [`FontPage`] page,
///
/// To also get the glyph’s bitmap and `advance` value
/// use [`get_page_glyph_with_bitmap`] instead.
///
/// This function is shorthand for [`Graphics::get_page_glyph`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`].
#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
#[inline(always)]
pub fn get_page_glyph(page: &FontPage, c: u32) -> Result<Glyph, Error> {
Graphics::Default().get_page_glyph(page, c)
}
/// Returns an [`Glyph`] object for character `c` in [`FontPage`] page,
/// and optionally returns the glyph’s bitmap and `advance` value.
///
/// If bitmap is not needed, use [`get_page_glyph`] instead.
///
/// This function is shorthand for [`Graphics::get_page_glyph_with_bitmap`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`].
#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
#[inline(always)]
pub fn get_page_glyph_with_bitmap<'p>(page: &'p FontPage,
c: u32,
advance: &mut c_int)
-> Result<(Glyph, BitmapRef<'p>), Error> {
Graphics::Default().get_page_glyph_with_bitmap(page, c, advance)
}
/// Returns an [`FontPage`] object for the given character code `c`.
///
/// Each [`FontPage`] contains information for 256 characters;
/// specifically, if `(c1 & ~0xff) == (c2 & ~0xff)`,
/// then `c1` and `c2` belong to the same page and the same [`FontPage`]
/// can be used to fetch the character data for both instead of searching for the page twice.
///
/// This function is shorthand for [`Graphics::get_font_page`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getFontPage`].
#[doc(alias = "sys::ffi::playdate_graphics::getFontPage")]
#[inline(always)]
pub fn get_font_page(font: &Font, c: u32) -> Result<FontPage, Error> {
Graphics::Default().get_font_page(font, c)
}
/// Returns the [`Font`] object for the font file at `path`.
///
/// This function is shorthand for [`Graphics::load_font`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::loadFont`].
#[doc(alias = "sys::ffi::playdate_graphics::loadFont")]
#[inline(always)]
pub fn load_font<P: AsRef<Path>>(path: P) -> Result<Font, ApiError> { Graphics::Default().load_font(path) }
/// ⚠️ Caution: This function is not tested.
///
/// Returns an [`Font`] object wrapping the LCDFontData data
/// comprising the contents (minus 16-byte header) of an uncompressed pft file.
///
/// The `wide` corresponds to the flag in the header indicating
/// whether the font contains glyphs at codepoints above `U+1FFFF`.
///
/// This function is shorthand for [`Graphics::make_font_from_bytes`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::makeFontFromData`].
#[doc(alias = "sys::ffi::playdate_graphics::makeFontFromData")]
#[inline(always)]
pub fn make_font_from_bytes(data: &[u8], wide: c_int) -> Result<Font, Error> {
Graphics::Default().make_font_from_bytes(data, wide)
}
/// Sets the leading adjustment (added to the leading specified in the font) to use when drawing text.
///
/// This function is shorthand for [`Graphics::set_text_leading`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setTextLeading`].
#[doc(alias = "sys::ffi::playdate_graphics::setTextLeading")]
#[inline(always)]
pub fn set_text_leading(line_height_adjustment: c_int) {
Graphics::Default().set_text_leading(line_height_adjustment)
}
/// Sets the tracking to use when drawing text.
///
/// This function is shorthand for [`Graphics::set_text_tracking`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setTextTracking`].
#[doc(alias = "sys::ffi::playdate_graphics::setTextTracking")]
#[inline(always)]
pub fn set_text_tracking(tracking: c_int) { Graphics::Default().set_text_tracking(tracking) }
/// Gets the tracking used when drawing text.
///
/// This function is shorthand for [`Graphics::set_text_tracking`],
/// using default ZST end-point.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextTracking`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextTracking")]
#[inline(always)]
#[cfg(feature = "sdk_2_1")]
pub fn get_text_tracking() -> c_int { Graphics::Default().get_text_tracking() }
impl<Api: crate::api::Api> Graphics<Api> {
/// Draws the given `text` using the provided coords `x`, `y`.
///
/// Encoding is always `StringEncoding::UTF8`.
/// If another encoding is desired, use [`draw_text_cstr`] instead.
///
/// If no `font` has been set with [`set_font`],
/// the default system font `Asheville Sans 14 Light` is used.
///
/// Equivalent to [`sys::ffi::playdate_graphics::drawText`].
#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
pub fn draw_text<S: AsRef<str>>(&self, text: S, x: c_int, y: c_int) -> Result<c_int, NulError> {
let s = CString::new(text.as_ref())?;
let f = self.0.draw_text();
let res = unsafe { f(s.as_ptr().cast(), text.as_ref().len(), StringEncoding::UTF8, x, y) };
Ok(res)
}
/// Draws the given `text` using the provided options.
///
/// If no `font` has been set with [`set_font`],
/// the default system font `Asheville Sans 14 Light` is used.
///
/// Same as [`draw_text`] but takes a [`sys::ffi::CStr`],
/// but little bit more efficient.
///
/// Equivalent to [`sys::ffi::playdate_graphics::drawText`].
#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
pub fn draw_text_cstr(&self, text: &CStr, encoding: StringEncoding, x: c_int, y: c_int) -> c_int {
let f = self.0.draw_text();
let len = text.to_bytes().len();
unsafe { f(text.as_ptr().cast(), len, encoding, x, y) }
}
/// Returns the width of the given `text` in the given `font`.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
pub fn get_text_width<S: AsRef<str>>(&self,
text: S,
font: Option<&Font>,
tracking: c_int)
-> Result<c_int, NulError> {
let s = CString::new(text.as_ref())?;
let f = self.0.get_text_width();
let font = font.map(|font| unsafe { font.as_raw() })
.unwrap_or(core::ptr::null_mut());
let res = unsafe {
f(
font,
s.as_ptr().cast(),
text.as_ref().len(),
StringEncoding::UTF8,
tracking,
)
};
Ok(res)
}
/// Returns the width of the given `text` in the given `font`.
///
/// Same as [`get_text_width`] but takes a [`sys::ffi::CStr`],
/// but little bit more efficient.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
pub fn get_text_width_cstr(&self,
text: &CStr,
encoding: StringEncoding,
font: Option<&Font>,
tracking: c_int)
-> c_int {
let f = self.0.get_text_width();
let len = text.to_bytes().len();
let font = font.map(|font| unsafe { font.as_raw() })
.unwrap_or(core::ptr::null_mut());
unsafe { f(font, text.as_ptr().cast(), len, encoding, tracking) }
}
/// Returns the height of the given `font`.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getFontHeight`].
#[doc(alias = "sys::ffi::playdate_graphics::getFontHeight")]
pub fn get_font_height(&self, font: &Font) -> u8 {
let f = self.0.get_font_height();
unsafe { f(font.as_raw()) }
}
/// Sets the `font` to use in subsequent [`draw_text`] calls.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setFont`].
#[doc(alias = "sys::ffi::playdate_graphics::setFont")]
pub fn set_font(&self, font: &Font) {
let f = self.0.set_font();
unsafe { f(font.as_raw()) }
}
/// Returns the kerning adjustment between characters `glyph_code` and `next_code` as specified by the font
///
/// Equivalent to [`sys::ffi::playdate_graphics::getGlyphKerning`].
#[doc(alias = "sys::ffi::playdate_graphics::getGlyphKerning")]
pub fn get_glyph_kerning(&self, glyph: &Glyph, glyph_code: u32, next_code: u32) -> c_int {
let f = self.0.get_glyph_kerning();
unsafe { f(glyph.as_raw(), glyph_code, next_code) }
}
/// Returns an [`Glyph`] object for character `c` in [`FontPage`] page,
///
/// To also get the glyph’s bitmap and `advance` value
/// use [`get_page_glyph_with_bitmap`] instead.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`].
#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
pub fn get_page_glyph(&self, page: &FontPage, c: u32) -> Result<Glyph, Error> {
let f = self.0.get_page_glyph();
let ptr = unsafe { f(page.as_raw(), c, core::ptr::null_mut(), core::ptr::null_mut()) };
if ptr.is_null() {
Err(Error::Font)
} else {
Ok(Glyph(ptr))
}
}
/// Returns an [`Glyph`] object for character `c` in [`FontPage`] page,
/// and optionally returns the glyph’s bitmap and `advance` value.
///
/// If bitmap is not needed, use [`get_page_glyph`] instead.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`].
#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
pub fn get_page_glyph_with_bitmap<'p>(&self,
page: &'p FontPage,
c: u32,
advance: &mut c_int)
-> Result<(Glyph, BitmapRef<'p>), Error> {
let bitmap = Box::new(core::ptr::null_mut() as *mut LCDBitmap);
let out_bitmap = Box::into_raw(bitmap);
let f = self.0.get_page_glyph();
let ptr = unsafe { f(page.as_raw(), c, out_bitmap, advance) };
if ptr.is_null() {
Err(Error::Font)
} else {
let bitmap = unsafe { Box::from_raw(out_bitmap) };
if bitmap.is_null() {
Err(Error::Font)
} else {
Ok((Glyph(ptr), BitmapRef::from(*bitmap)))
}
}
}
/// Returns an [`FontPage`] object for the given character code `c`.
///
/// Each [`FontPage`] contains information for 256 characters;
/// specifically, if `(c1 & ~0xff) == (c2 & ~0xff)`,
/// then `c1` and `c2` belong to the same page and the same [`FontPage`]
/// can be used to fetch the character data for both instead of searching for the page twice.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getFontPage`].
#[doc(alias = "sys::ffi::playdate_graphics::getFontPage")]
pub fn get_font_page(&self, font: &Font, c: u32) -> Result<FontPage, Error> {
let f = self.0.get_font_page();
let ptr = unsafe { f(font.as_raw(), c) };
if ptr.is_null() {
Err(Error::Font)
} else {
Ok(FontPage(ptr))
}
}
/// Returns the [`Font`] object for the font file at `path`.
///
/// Equivalent to [`sys::ffi::playdate_graphics::loadFont`].
#[doc(alias = "sys::ffi::playdate_graphics::loadFont")]
pub fn load_font<P: AsRef<Path>>(&self, path: P) -> Result<Font, ApiError> {
let mut err = Box::new(core::ptr::null() as *const c_char);
let out_err = Box::into_raw(err);
let path = CString::new(path.as_ref())?;
let f = self.0.load_font();
let ptr = unsafe { f(path.as_ptr() as *mut c_char, out_err as _) };
if ptr.is_null() {
err = unsafe { Box::from_raw(out_err) };
if let Some(err) = fs::error::Error::from_ptr(*err) {
Err(Error::Fs(err).into())
} else {
Err(Error::Alloc.into())
}
} else {
Ok(Font(ptr))
}
}
/// ⚠️ Caution: This function is not tested.
///
/// Returns an [`Font`] object wrapping the LCDFontData data
/// comprising the contents (minus 16-byte header) of an uncompressed pft file.
///
/// The `wide` corresponds to the flag in the header indicating
/// whether the font contains glyphs at codepoints above `U+1FFFF`.
///
/// Equivalent to [`sys::ffi::playdate_graphics::makeFontFromData`].
#[doc(alias = "sys::ffi::playdate_graphics::makeFontFromData")]
pub fn make_font_from_bytes(&self, data: &[u8], wide: c_int) -> Result<Font, Error> {
let f = self.0.make_font_from_data();
let ptr = unsafe { f(data.as_ptr() as _, wide) };
if ptr.is_null() {
Err(Error::Alloc)
} else {
Ok(Font(ptr))
}
}
/// Sets the leading adjustment (added to the leading specified in the font) to use when drawing text.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setTextLeading`].
#[doc(alias = "sys::ffi::playdate_graphics::setTextLeading")]
pub fn set_text_leading(&self, line_height_adjustment: c_int) {
let f = self.0.set_text_leading();
unsafe { f(line_height_adjustment) }
}
/// Sets the tracking to use when drawing text.
///
/// Equivalent to [`sys::ffi::playdate_graphics::setTextTracking`].
#[doc(alias = "sys::ffi::playdate_graphics::setTextTracking")]
pub fn set_text_tracking(&self, tracking: c_int) {
let f = self.0.set_text_tracking();
unsafe { f(tracking) }
}
/// Sets the tracking to use when drawing text.
///
/// Equivalent to [`sys::ffi::playdate_graphics::getTextTracking`].
#[doc(alias = "sys::ffi::playdate_graphics::getTextTracking")]
#[cfg(feature = "sdk_2_1")]
pub fn get_text_tracking(&self) -> c_int {
let f = self.0.get_text_tracking();
unsafe { f() }
}
}
/// Playdate Font representation.
///
/// See [official docs][] for more information.
///
/// [official docs]: https://sdk.play.date/Inside%20Playdate.html#C-graphics.font
pub struct Font(*mut LCDFont);
impl AsRaw for Font {
type Type = LCDFont;
unsafe fn as_raw(&self) -> *mut Self::Type { self.0 }
}
/// Playdate Glyph representation.
pub struct Glyph(*mut LCDFontGlyph);
impl AsRaw for Glyph {
type Type = LCDFontGlyph;
unsafe fn as_raw(&self) -> *mut Self::Type { self.0 }
}
/// Playdate FontPage representation.
pub struct FontPage(*mut LCDFontPage);
impl AsRaw for FontPage {
type Type = LCDFontPage;
unsafe fn as_raw(&self) -> *mut Self::Type { self.0 }
}
pub trait StringEncodingExt {
#![allow(non_upper_case_globals)]
const ASCII: StringEncoding = StringEncoding::kASCIIEncoding;
const UTF8: StringEncoding = StringEncoding::kUTF8Encoding;
const LE16Bit: StringEncoding = StringEncoding::k16BitLEEncoding;
}
impl StringEncodingExt for StringEncoding {}
pub mod api {
use core::ffi::c_char;
use core::ffi::c_int;
use core::ffi::c_void;
use sys::ffi::LCDBitmap;
use sys::ffi::LCDFont;
use sys::ffi::LCDFontData;
use sys::ffi::LCDFontGlyph;
use sys::ffi::LCDFontPage;
use sys::ffi::PDStringEncoding;
/// Default graphics text api end-point, ZST.
///
/// All calls approximately costs ~3 derefs.
pub type Default = crate::api::Default;
/// Cached graphics text api end-point.
///
/// Stores one reference, so size on stack is eq `usize`.
///
/// All calls approximately costs ~1 deref.
pub type Cache = crate::api::Cache;
/// End-point with methods about ops with text.
pub trait Api {
/// Equivalent to [`sys::ffi::playdate_graphics::drawText`]
#[doc(alias = "sys::ffi::playdate_graphics::drawText")]
#[inline(always)]
fn draw_text(
&self)
-> unsafe extern "C" fn(text: *const c_void,
len: usize,
encoding: PDStringEncoding,
x: c_int,
y: c_int) -> c_int {
*sys::api!(graphics.drawText)
}
/// Equivalent to [`sys::ffi::playdate_graphics::getTextWidth`]
#[doc(alias = "sys::ffi::playdate_graphics::getTextWidth")]
#[inline(always)]
fn get_text_width(
&self)
-> unsafe extern "C" fn(font: *mut LCDFont,
text: *const c_void,
len: usize,
encoding: PDStringEncoding,
tracking: c_int) -> c_int {
*sys::api!(graphics.getTextWidth)
}
/// Equivalent to [`sys::ffi::playdate_graphics::getFontHeight`]
#[doc(alias = "sys::ffi::playdate_graphics::getFontHeight")]
#[inline(always)]
fn get_font_height(&self) -> unsafe extern "C" fn(font: *mut LCDFont) -> u8 {
*sys::api!(graphics.getFontHeight)
}
/// Equivalent to [`sys::ffi::playdate_graphics::setFont`]
#[doc(alias = "sys::ffi::playdate_graphics::setFont")]
#[inline(always)]
fn set_font(&self) -> unsafe extern "C" fn(font: *mut LCDFont) { *sys::api!(graphics.setFont) }
/// Equivalent to [`sys::ffi::playdate_graphics::setTextTracking`]
#[doc(alias = "sys::ffi::playdate_graphics::setTextTracking")]
#[inline(always)]
fn set_text_tracking(&self) -> unsafe extern "C" fn(tracking: c_int) {
*sys::api!(graphics.setTextTracking)
}
/// Equivalent to [`sys::ffi::playdate_graphics::getTextTracking`]
#[doc(alias = "sys::ffi::playdate_graphics::getTextTracking")]
#[inline(always)]
#[cfg(feature = "sdk_2_1")]
fn get_text_tracking(&self) -> unsafe extern "C" fn() -> c_int { *sys::api!(graphics.getTextTracking) }
/// Equivalent to [`sys::ffi::playdate_graphics::getGlyphKerning`]
#[doc(alias = "sys::ffi::playdate_graphics::getGlyphKerning")]
#[inline(always)]
fn get_glyph_kerning(
&self)
-> unsafe extern "C" fn(glyph: *mut LCDFontGlyph, glyphcode: u32, nextcode: u32) -> c_int {
*sys::api!(graphics.getGlyphKerning)
}
/// Equivalent to [`sys::ffi::playdate_graphics::loadFont`]
#[doc(alias = "sys::ffi::playdate_graphics::loadFont")]
#[inline(always)]
fn load_font(&self)
-> unsafe extern "C" fn(path: *const c_char, outErr: *mut *const c_char) -> *mut LCDFont {
*sys::api!(graphics.loadFont)
}
/// Equivalent to [`sys::ffi::playdate_graphics::getFontPage`]
#[doc(alias = "sys::ffi::playdate_graphics::getFontPage")]
#[inline(always)]
fn get_font_page(&self) -> unsafe extern "C" fn(font: *mut LCDFont, c: u32) -> *mut LCDFontPage {
*sys::api!(graphics.getFontPage)
}
/// Equivalent to [`sys::ffi::playdate_graphics::getPageGlyph`]
#[doc(alias = "sys::ffi::playdate_graphics::getPageGlyph")]
#[inline(always)]
fn get_page_glyph(
&self)
-> unsafe extern "C" fn(page: *mut LCDFontPage,
c: u32,
bitmap: *mut *mut LCDBitmap,
advance: *mut c_int) -> *mut LCDFontGlyph {
*sys::api!(graphics.getPageGlyph)
}
/// Equivalent to [`sys::ffi::playdate_graphics::makeFontFromData`]
#[doc(alias = "sys::ffi::playdate_graphics::makeFontFromData")]
#[inline(always)]
fn make_font_from_data(&self) -> unsafe extern "C" fn(data: *mut LCDFontData, wide: c_int) -> *mut LCDFont {
*sys::api!(graphics.makeFontFromData)
}
/// Equivalent to [`sys::ffi::playdate_graphics::setTextLeading`]
#[doc(alias = "sys::ffi::playdate_graphics::setTextLeading")]
#[inline(always)]
fn set_text_leading(&self) -> unsafe extern "C" fn(lineHeightAdustment: c_int) {
*sys::api!(graphics.setTextLeading)
}
}
}