// GENERATED — DO NOT EDIT

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/struct.GlyphString.html).
pub type GlyphString

///|
pub(open) trait IGlyphString {
  fn as_glyph_string(Self) -> GlyphString
  fn extents(Self, &IFont) -> (Rectangle, Rectangle) = _
  fn extents_range(Self, Int, Int, &IFont) -> (Rectangle, Rectangle) = _
  fn get_logical_widths(Self, String, Int, Int) -> Array[Int] = _
  fn get_width(Self) -> Int = _
  fn index_to_x(Self, String, Int, Analysis, Int, Bool) -> Int = _
  fn index_to_x_full(
    Self,
    String,
    Int,
    Analysis,
    FixedArray[LogAttr]?,
    Int,
    Bool,
  ) -> Int = _
  fn set_size(Self, Int) -> Unit = _
  fn x_to_index(Self, String, Int, Analysis, Int) -> (Int, Int) = _
}

///|
pub impl IGlyphString for GlyphString with fn as_glyph_string(self) {
  self
}

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/ctor.GlyphString.new.html).
pub extern "c" fn GlyphString::new() -> GlyphString = "moonbit_pango_glyph_string_new"

///|
#borrow(self_, font, __out_logical_rect)
extern "c" fn moonbit_pango_glyph_string_extents(
  self_ : GlyphString,
  font : Font,
  __out_logical_rect : Ref[Rectangle],
) -> Rectangle = "moonbit_pango_glyph_string_extents"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.extents.html).
pub fn GlyphString::extents(
  self : GlyphString,
  font : &IFont,
) -> (Rectangle, Rectangle) {
  let __out_logical_rect = Ref(Rectangle::_zero())
  let __result = moonbit_pango_glyph_string_extents(
    self,
    font.as_font(),
    __out_logical_rect,
  )
  (__result, __out_logical_rect.val)
}

///|
#borrow(self_, font, __out_logical_rect)
extern "c" fn moonbit_pango_glyph_string_extents_range(
  self_ : GlyphString,
  start : Int,
  end : Int,
  font : Font,
  __out_logical_rect : Ref[Rectangle],
) -> Rectangle = "moonbit_pango_glyph_string_extents_range"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.extents_range.html).
pub fn GlyphString::extents_range(
  self : GlyphString,
  start : Int,
  end : Int,
  font : &IFont,
) -> (Rectangle, Rectangle) {
  let __out_logical_rect = Ref(Rectangle::_zero())
  let __result = moonbit_pango_glyph_string_extents_range(
    self,
    start,
    end,
    font.as_font(),
    __out_logical_rect,
  )
  (__result, __out_logical_rect.val)
}

///|
#borrow(self_, text, logical_widths)
extern "c" fn moonbit_pango_glyph_string_get_logical_widths(
  self_ : GlyphString,
  text : Bytes,
  length : Int,
  embedding_level : Int,
  logical_widths : Ref[FixedArray[Int]],
) = "moonbit_pango_glyph_string_get_logical_widths"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.get_logical_widths.html).
pub fn GlyphString::get_logical_widths(
  self : GlyphString,
  text : String,
  length : Int,
  embedding_level : Int,
) -> Array[Int] {
  let logical_widths : Ref[FixedArray[Int]] = Ref([])
  moonbit_pango_glyph_string_get_logical_widths(
    self,
    @encoding/utf8.encode(text),
    length,
    embedding_level,
    logical_widths,
  )
  let result : Array[Int] = Array::new(capacity=logical_widths.val.length())
  for i in 0.. Int = "moonbit_pango_glyph_string_get_width"

///|
#borrow(self_, text, analysis, x_pos)
extern "c" fn moonbit_pango_glyph_string_index_to_x(
  self_ : GlyphString,
  text : Bytes,
  length : Int,
  analysis : Analysis,
  index_ : Int,
  trailing : Bool,
  x_pos : Ref[Int],
) = "moonbit_pango_glyph_string_index_to_x"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.index_to_x.html).
pub fn GlyphString::index_to_x(
  self : GlyphString,
  text : String,
  length : Int,
  analysis : Analysis,
  index_ : Int,
  trailing : Bool,
) -> Int {
  let x_pos = Ref(0)
  moonbit_pango_glyph_string_index_to_x(
    self,
    @encoding/utf8.encode(text),
    length,
    analysis,
    index_,
    trailing,
    x_pos,
  )
  x_pos.val
}

///|
#borrow(self_, text, analysis, attrs, x_pos)
extern "c" fn moonbit_pango_glyph_string_index_to_x_full(
  self_ : GlyphString,
  text : Bytes,
  length : Int,
  analysis : Analysis,
  attrs : @glib.Nullable[Ref[FixedArray[LogAttr]]],
  index_ : Int,
  trailing : Bool,
  x_pos : Ref[Int],
) = "moonbit_pango_glyph_string_index_to_x_full"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.index_to_x_full.html).
pub fn GlyphString::index_to_x_full(
  self : GlyphString,
  text : String,
  length : Int,
  analysis : Analysis,
  attrs : FixedArray[LogAttr]?,
  index_ : Int,
  trailing : Bool,
) -> Int {
  let attrs_ref : @glib.Nullable[Ref[FixedArray[LogAttr]]] = match attrs {
    Some(values) => @glib.Nullable::some(Ref(values))
    None => @glib.Nullable::null()
  }
  let x_pos = Ref(0)
  moonbit_pango_glyph_string_index_to_x_full(
    self,
    @encoding/utf8.encode(text),
    length,
    analysis,
    attrs_ref,
    index_,
    trailing,
    x_pos,
  )
  x_pos.val
}

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.set_size.html).
#borrow(self)
pub extern "c" fn GlyphString::set_size(self : GlyphString, new_len : Int) = "moonbit_pango_glyph_string_set_size"

///|
#borrow(self_, text, analysis, index_, trailing)
extern "c" fn moonbit_pango_glyph_string_x_to_index(
  self_ : GlyphString,
  text : Bytes,
  length : Int,
  analysis : Analysis,
  x_pos : Int,
  index_ : Ref[Int],
  trailing : Ref[Int],
) = "moonbit_pango_glyph_string_x_to_index"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/method.GlyphString.x_to_index.html).
pub fn GlyphString::x_to_index(
  self : GlyphString,
  text : String,
  length : Int,
  analysis : Analysis,
  x_pos : Int,
) -> (Int, Int) {
  let index_ = Ref(0)
  let trailing = Ref(0)
  moonbit_pango_glyph_string_x_to_index(
    self,
    @encoding/utf8.encode(text),
    length,
    analysis,
    x_pos,
    index_,
    trailing,
  )
  (index_.val, trailing.val)
}

///|
impl IGlyphString with fn extents(self, font) -> (Rectangle, Rectangle) {
  self.as_glyph_string().extents(font)
}

///|
impl IGlyphString with fn extents_range(self, start, end, font) -> (
  Rectangle,
  Rectangle,
) {
  self.as_glyph_string().extents_range(start, end, font)
}

///|
impl IGlyphString with fn get_logical_widths(
  self,
  text,
  length,
  embedding_level,
) -> Array[Int] {
  self.as_glyph_string().get_logical_widths(text, length, embedding_level)
}

///|
impl IGlyphString with fn get_width(self) -> Int {
  self.as_glyph_string().get_width()
}

///|
impl IGlyphString with fn index_to_x(
  self,
  text,
  length,
  analysis,
  index_,
  trailing,
) -> Int {
  self.as_glyph_string().index_to_x(text, length, analysis, index_, trailing)
}

///|
impl IGlyphString with fn index_to_x_full(
  self,
  text,
  length,
  analysis,
  attrs,
  index_,
  trailing,
) -> Int {
  self
  .as_glyph_string()
  .index_to_x_full(text, length, analysis, attrs, index_, trailing)
}

///|
impl IGlyphString with fn set_size(self, new_len) -> Unit {
  self.as_glyph_string().set_size(new_len)
}

///|
impl IGlyphString with fn x_to_index(self, text, length, analysis, x_pos) -> (
  Int,
  Int,
) {
  self.as_glyph_string().x_to_index(text, length, analysis, x_pos)
}

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/struct.GlyphString.html).
#borrow(self_)
pub extern "c" fn GlyphString::get_num_glyphs(self_ : GlyphString) -> Int = "moonbit_pango_glyph_string_num_glyphs_get"

///|
#borrow(self_, values)
extern "c" fn __ffi_moonbit_pango_glyph_string_glyphs_get(
  self_ : GlyphString,
  values : Ref[FixedArray[GlyphInfo]],
) = "moonbit_pango_glyph_string_glyphs_get"

///|
/// [Upstream documentation](https://gnome.pages.gitlab.gnome.org/pango/Pango/struct.GlyphString.html).
pub fn GlyphString::get_glyphs(self : GlyphString) -> Array[GlyphInfo] {
  let values : Ref[FixedArray[GlyphInfo]] = Ref([])
  __ffi_moonbit_pango_glyph_string_glyphs_get(self, values)
  Array::from_fixed_array(values.val)
}