<alto xmlns="http://www.loc.gov/standards/alto/ns-v3#">
	<Description>
		<MeasurementUnit>pixel</MeasurementUnit>
		<sourceImageInformation>
			<fileName>{{ page.name }}</fileName>
		</sourceImageInformation>
		<OCRProcessing ID="OCR_0">
			<ocrProcessingStep>
				<processingSoftware>
					<softwareName>kraken</softwareName>
				</processingSoftware>
			</ocrProcessingStep>
		</OCRProcessing>
	</Description>

	<Layout>
		<Page WIDTH="{{ page.size[0] }}" HEIGHT="{{ page.size[1] }}" PHYSICAL_IMG_NR="0" ID="page_0">
			<PrintSpace HPOS="0" VPOS="0" WIDTH="{{ page.size[0] }}" HEIGHT="{{ page.size[1] }}">
				<TextBlock HPOS="0" VPOS="0" ID="textblock_0" WIDTH="{{ page.size[0] }}" HEIGHT="{{ page.size[1] }}">
					{% for line in page.lines %}
					<TextLine ID="line_{{ line.index }}"
						  HPOS="{{ line.bbox[0] }}"
						  VPOS="{{ line.bbox[1] }}" 
						  WIDTH="{{ line.bbox[2] - line.bbox[0] }}" 
						  HEIGHT="{{ line.bbox[3] - line.bbox[1] }}">
						{% for segment in line.recognition %}
							{# ALTO forbids encoding whitespace before any String/Shape tags #}
							{% if segment.text is whitespace and loop.index > 1 %}
							<SP ID="segment_{{ segment.index }}"
							    HPOS="{{ segment.bbox[0]}}" 
							    VPOS="{{ segment.bbox[1] }}"
							    WIDTH="{{ segment.bbox[2] - segment.bbox[0] }}" 
							    HEIGHT="{{ segment.bbox[3] - segment.bbox[1] }}"/>
							{% else %}
							<String ID="segment_{{ segment.index }}"
								CONTENT="{{ segment.text|e }}" 
								HPOS="{{ segment.bbox[0]}}" 
								VPOS="{{ segment.bbox[1] }}"
								WIDTH="{{ segment.bbox[2] - segment.bbox[0] }}" 
								HEIGHT="{{ segment.bbox[3] - segment.bbox[1] }}" 
								WC="{{ (segment.confidences|sum / segment.confidences|length)|round(4) }}"
								CC="{{ segment.confidences|rescale(9, 0)|map('round')|map('int')|join(' ') }}"/>
							{% endif %}
						{% endfor %}
					</TextLine>
					{% endfor %}
				</TextBlock>
			</PrintSpace>
		</Page>
	</Layout>
</alto>
