| 1 |
// SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
| 2 |
// Copyright (C) 2012 SIL International |
| 3 |
using System; |
| 4 |
|
| 5 |
namespace NGraphite |
| 6 |
{ |
| 7 |
public class Slot |
| 8 |
{ |
| 9 |
IntPtr _slot; |
| 10 |
|
| 11 |
internal Slot(IntPtr slot) |
| 12 |
{ |
| 13 |
_slot = slot; |
| 14 |
} |
| 15 |
|
| 16 |
internal IntPtr SlotPtr |
| 17 |
{ |
| 18 |
get { return _slot; } |
| 19 |
} |
| 20 |
|
| 21 |
public Slot NextInSegment |
| 22 |
{ |
| 23 |
get |
| 24 |
{ |
| 25 |
return CreateSlotOrReturnNull(Graphite2Api.SlotNextInSegment(_slot)); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
public Slot PrevInSegment |
| 30 |
{ |
| 31 |
get |
| 32 |
{ |
| 33 |
return CreateSlotOrReturnNull(Graphite2Api.SlotPrevInSegment(_slot)); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
public Slot AttachedTo |
| 38 |
{ |
| 39 |
get |
| 40 |
{ |
| 41 |
return CreateSlotOrReturnNull(Graphite2Api.SlotAttachedTo(_slot)); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
public Slot FirstAttachment |
| 46 |
{ |
| 47 |
get |
| 48 |
{ |
| 49 |
return CreateSlotOrReturnNull(Graphite2Api.SlotFirstAttachment(_slot)); |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
public Slot NextSiblingAttachment |
| 54 |
{ |
| 55 |
get |
| 56 |
{ |
| 57 |
return CreateSlotOrReturnNull(Graphite2Api.SlotNextSiblingAttachment(_slot)); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public ushort Gid |
| 62 |
{ |
| 63 |
get |
| 64 |
{ |
| 65 |
return Graphite2Api.SlotGid(_slot); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
public float OriginX |
| 70 |
{ |
| 71 |
get |
| 72 |
{ |
| 73 |
return Graphite2Api.SlotOriginX(_slot); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
public float OriginY |
| 78 |
{ |
| 79 |
get |
| 80 |
{ |
| 81 |
return Graphite2Api.SlotOriginY(_slot); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public int Before |
| 86 |
{ |
| 87 |
get |
| 88 |
{ |
| 89 |
return Graphite2Api.SlotBefore(_slot); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
public int After |
| 94 |
{ |
| 95 |
get |
| 96 |
{ |
| 97 |
return Graphite2Api.SlotAfter(_slot); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
public uint Index |
| 102 |
{ |
| 103 |
get |
| 104 |
{ |
| 105 |
return Graphite2Api.SlotIndex(_slot); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
public bool CanInsertBefore |
| 110 |
{ |
| 111 |
get { return Graphite2Api.SlotCanInsertBefore(_slot) != 0; } |
| 112 |
} |
| 113 |
|
| 114 |
public int Original |
| 115 |
{ |
| 116 |
get { return Graphite2Api.SlotOriginal(_slot); } |
| 117 |
} |
| 118 |
|
| 119 |
public float AdvanceX(Face face, Font font) |
| 120 |
{ |
| 121 |
return Graphite2Api.SlotAdvanceX(_slot, face.FacePtr, font.FontPtr); |
| 122 |
} |
| 123 |
|
| 124 |
public float AdvanceY(Face face, Font font) |
| 125 |
{ |
| 126 |
return Graphite2Api.SlotAdvanceY(_slot, face.FacePtr, font.FontPtr); |
| 127 |
} |
| 128 |
|
| 129 |
public int Attr(Segment seg, AttrCode index, byte subindex) |
| 130 |
{ |
| 131 |
return Graphite2Api.SlotAttr(_slot, seg.SegPtr, index, subindex); |
| 132 |
} |
| 133 |
|
| 134 |
public void LineBreakBefore() |
| 135 |
{ |
| 136 |
Graphite2Api.SlotLinebreakBefore(_slot); |
| 137 |
} |
| 138 |
|
| 139 |
#region Helper Methods |
| 140 |
/// <summary> |
| 141 |
/// Creates the slot or return null of slotPtr == IntPtr.Zero. |
| 142 |
/// </summary> |
| 143 |
/// <returns> |
| 144 |
/// a slot or null. |
| 145 |
/// </returns> |
| 146 |
/// <param name='slotPtr'> |
| 147 |
/// Slot ptr. |
| 148 |
/// </param> |
| 149 |
private Slot CreateSlotOrReturnNull(IntPtr slotPtr) |
| 150 |
{ |
| 151 |
if (slotPtr == IntPtr.Zero) |
| 152 |
return null; |
| 153 |
return new Slot(slotPtr); |
| 154 |
} |
| 155 |
#endregion |
| 156 |
} |
| 157 |
} |
| 158 |
|