package harfbuzz

import fontP 

func simpleKern( fontP.Kernx) fontP.SimpleKerns {
	for ,  := range  {
		if ,  := .Data.(fontP.SimpleKerns);  {
			return 
		}
	}
	return nil
}

func kern( fontP.SimpleKerns,  bool,  *Font,  *Buffer,  GlyphMask,  bool) {
	.unsafeToConcat(0, maxInt)

	var  otApplyContext

	.reset(1, , )
	.setLookupMask()
	.setLookupProps(uint32(otIgnoreMarks))
	 := &.iterInput
	 := .Props.Direction.isHorizontal()
	 := .Info
	 := .Pos
	for  := 0;  < len(); {
		if [].Mask& == 0 {
			++
			continue
		}

		.resetFast()
		if ,  := .next(); ! {
			++
			continue
		}

		 := 
		 := .idx

		 := .KernPair([].Glyph, [].Glyph)
		 := Position()

		if  == 0 {
			goto 
		}

		if  {
			if  {
				 = .emScaleX()
			}
			if  {
				[].YOffset = 
				.scratchFlags |= bsfHasGPOSAttachment
			} else {
				 :=  >> 1
				 :=  - 
				[].XAdvance += 
				[].XAdvance += 
				[].XOffset += 
			}
		} else {
			if  {
				 = .emScaleY()
			}
			if  {
				[].XOffset = 
				.scratchFlags |= bsfHasGPOSAttachment
			} else {
				 :=  >> 1
				 :=  - 
				[].YAdvance += 
				[].YAdvance += 
				[].YOffset += 
			}
		}

		.unsafeToBreak(, +1)

	:
		 = .idx
	}
}

func ( *otShapePlan) ( *Font,  *Buffer) {
	 := .Props.Direction.isBackward()

	if  {
		.Reverse()
	}

	if  := simpleKern(.face.Kern);  != nil {
		kern(, false, , , .kernMask, false)
	}

	if  {
		.Reverse()
	}
}