gr_slot.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later
  2. // Copyright 2010, SIL International, All rights reserved.
  3. #include "graphite2/Segment.h"
  4. #include "inc/Segment.h"
  5. #include "inc/Slot.h"
  6. #include "inc/Font.h"
  7. extern "C" {
  8. const gr_slot* gr_slot_next_in_segment(const gr_slot* p/*not NULL*/)
  9. {
  10. assert(p);
  11. return static_cast<const gr_slot*>(p->next());
  12. }
  13. const gr_slot* gr_slot_prev_in_segment(const gr_slot* p/*not NULL*/)
  14. {
  15. assert(p);
  16. return static_cast<const gr_slot*>(p->prev());
  17. }
  18. const gr_slot* gr_slot_attached_to(const gr_slot* p/*not NULL*/) //returns NULL iff base. If called repeatedly on result, will get to a base
  19. {
  20. assert(p);
  21. return static_cast<const gr_slot*>(p->attachedTo());
  22. }
  23. const gr_slot* gr_slot_first_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no attachments.
  24. { //if slot_first_attachment(p) is not NULL, then slot_attached_to(slot_first_attachment(p))==p.
  25. assert(p);
  26. return static_cast<const gr_slot*>(p->firstChild());
  27. }
  28. const gr_slot* gr_slot_next_sibling_attachment(const gr_slot* p/*not NULL*/) //returns NULL iff no more attachments.
  29. { //if slot_next_sibling_attachment(p) is not NULL, then slot_attached_to(slot_next_sibling_attachment(p))==slot_attached_to(p).
  30. assert(p);
  31. return static_cast<const gr_slot*>(p->nextSibling());
  32. }
  33. unsigned short gr_slot_gid(const gr_slot* p/*not NULL*/)
  34. {
  35. assert(p);
  36. return p->glyph();
  37. }
  38. float gr_slot_origin_X(const gr_slot* p/*not NULL*/)
  39. {
  40. assert(p);
  41. return p->origin().x;
  42. }
  43. float gr_slot_origin_Y(const gr_slot* p/*not NULL*/)
  44. {
  45. assert(p);
  46. return p->origin().y;
  47. }
  48. float gr_slot_advance_X(const gr_slot* p/*not NULL*/, const gr_face *face, const gr_font *font)
  49. {
  50. assert(p);
  51. float scale = 1.0;
  52. float res = p->advance();
  53. if (font)
  54. {
  55. scale = font->scale();
  56. int gid = p->glyph();
  57. if (face && font->isHinted() && gid < face->glyphs().numGlyphs())
  58. res = (res - face->glyphs().glyph(gid)->theAdvance().x) * scale + font->advance(gid);
  59. else
  60. res = res * scale;
  61. }
  62. return res;
  63. }
  64. float gr_slot_advance_Y(const gr_slot *p/*not NULL*/, GR_MAYBE_UNUSED const gr_face *face, const gr_font *font)
  65. {
  66. assert(p);
  67. float res = p->advancePos().y;
  68. if (font)
  69. return res * font->scale();
  70. else
  71. return res;
  72. }
  73. int gr_slot_before(const gr_slot* p/*not NULL*/)
  74. {
  75. assert(p);
  76. return p->before();
  77. }
  78. int gr_slot_after(const gr_slot* p/*not NULL*/)
  79. {
  80. assert(p);
  81. return p->after();
  82. }
  83. unsigned int gr_slot_index(const gr_slot *p/*not NULL*/)
  84. {
  85. assert(p);
  86. return p->index();
  87. }
  88. int gr_slot_attr(const gr_slot* p/*not NULL*/, const gr_segment* pSeg/*not NULL*/, gr_attrCode index, gr_uint8 subindex)
  89. {
  90. assert(p);
  91. return p->getAttr(pSeg, index, subindex);
  92. }
  93. int gr_slot_can_insert_before(const gr_slot* p/*not NULL*/)
  94. {
  95. assert(p);
  96. return (p->isInsertBefore())? 1 : 0;
  97. }
  98. int gr_slot_original(const gr_slot* p/*not NULL*/)
  99. {
  100. assert(p);
  101. return p->original();
  102. }
  103. void gr_slot_linebreak_before(gr_slot* p/*not NULL*/)
  104. {
  105. assert(p);
  106. gr_slot *prev = (gr_slot *)p->prev();
  107. prev->sibling(NULL);
  108. prev->next(NULL);
  109. p->prev(NULL);
  110. }
  111. #if 0 //what should this be
  112. size_t id(const gr_slot* p/*not NULL*/)
  113. {
  114. return (size_t)p->id();
  115. }
  116. #endif
  117. } // extern "C"