github.com/signintech/pdft@v0.5.0/minigopdf/map_of_character_To_glyph_index.go (about)

     1  package gopdf
     2  
     3  // MapOfCharacterToGlyphIndex map of CharacterToGlyphIndex
     4  type MapOfCharacterToGlyphIndex struct {
     5  	keyIndexs map[rune]int //for search index in keys
     6  	Keys      []rune
     7  	Vals      []uint
     8  }
     9  
    10  // NewMapOfCharacterToGlyphIndex new CharacterToGlyphIndex
    11  func NewMapOfCharacterToGlyphIndex() *MapOfCharacterToGlyphIndex {
    12  	var m MapOfCharacterToGlyphIndex
    13  	m.keyIndexs = make(map[rune]int)
    14  	return &m
    15  }
    16  
    17  // KeyExists key is exists?
    18  func (m *MapOfCharacterToGlyphIndex) KeyExists(k rune) bool {
    19  	/*for _, key := range m.Keys {
    20  		if k == key {
    21  			return true
    22  		}
    23  	}*/
    24  	if _, ok := m.keyIndexs[k]; ok {
    25  		return true
    26  	}
    27  	return false
    28  }
    29  
    30  // Set set key and value to map
    31  func (m *MapOfCharacterToGlyphIndex) Set(k rune, v uint) {
    32  	m.keyIndexs[k] = len(m.Keys)
    33  	m.Keys = append(m.Keys, k)
    34  	m.Vals = append(m.Vals, v)
    35  }
    36  
    37  // Index get index by key
    38  func (m *MapOfCharacterToGlyphIndex) Index(k rune) (int, bool) {
    39  	/*for i, key := range m.Keys {
    40  		if k == key {
    41  			return i, true
    42  		}
    43  	}*/
    44  	if index, ok := m.keyIndexs[k]; ok {
    45  		return index, true
    46  	}
    47  	return -1, false
    48  }
    49  
    50  // Val get value by Key
    51  func (m *MapOfCharacterToGlyphIndex) Val(k rune) (uint, bool) {
    52  	i, ok := m.Index(k)
    53  	if !ok {
    54  		return 0, false
    55  	}
    56  	return m.Vals[i], true
    57  }
    58  
    59  // AllKeys get keys
    60  func (m *MapOfCharacterToGlyphIndex) AllKeys() []rune {
    61  	return m.Keys
    62  }
    63  
    64  // AllVals get all values
    65  func (m *MapOfCharacterToGlyphIndex) AllVals() []uint {
    66  	return m.Vals
    67  }