// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/graphics/backends/cairo/fontcairo.cpp
// Function: smooth::GUI::FontCairo::GetTextSize(smooth::String const&) const
S::GUI::Size S::GUI::FontCairo::GetTextSize(const String &iText) const
{
	if (iText == NIL) return Size();

	String	 text	    = iText;
	Int	 textLength = text.Length();

	/* Set up Cairo font and calculate text size.
	 */
	Float		 dpi	 = Surface().GetSurfaceDPI();

	cairo_surface_t	*surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
	cairo_t		*context = cairo_create(surface);

	PangoLayout		*layout	= pango_cairo_create_layout(context);
	PangoFontDescription	*desc	= pango_font_description_from_string(String(fontName)
									    .Append(" ")
									    .Append(fontStyle & Font::Italic ? "Italic " : "")
									    .Append(fontWeight >= Font::Bold ? "Bold " : "")
									    .Append(String::FromInt(Math::Round(fontSize * dpi / 96.0))));

	if (textLength > 0) pango_layout_set_text(layout, text.ConvertTo("UTF-8"), -1);

	pango_layout_set_font_description(layout, desc);
	pango_font_description_free(desc);

	int	 x = 0;
	int	 y = 0;

	pango_layout_get_pixel_size(layout, &x, &y);

	g_object_unref(layout);

	cairo_destroy(context);
	cairo_surface_destroy(surface);

	return Size(x, y - 2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movq %rdi, %r12
xorl %ebx, %ebx
movq %rsi, %rdi
xorl %esi, %esi
callq 0x55260
testb %al, %al
jne 0xc4740
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x570b0
movq %rbx, %rdi
callq 0x57180
movl %eax, %ebx
leaq 0x28(%rsp), %rdx
movq $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x57150
movl %ebx, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
callq 0x58930
movl %eax, %r13d
leaq 0x10(%rsp), %rdi
callq 0x57b20
xorl %edi, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x57000
movq %rax, %r14
movq %rax, %rdi
callq 0x58060
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x586d0
movq %rax, %r15
leaq 0x10(%r12), %rsi
leaq 0x10(%rsp), %rdi
callq 0x570b0
leaq 0x64e6b(%rip), %rsi     # 0x1293f0
leaq 0x28(%rsp), %rdi
callq 0x579f0
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x562f0
movq %rax, %rbp
movq 0xa89b0(%rip), %rax     # 0x16cf58
movzwl (%rax), %eax
testw %ax, 0x3a(%r12)
leaq 0x4e2cc(%rip), %rbx     # 0x112884
leaq 0x4fea2(%rip), %rsi     # 0x114461
cmoveq %rbx, %rsi
leaq 0x78(%rsp), %rdi
callq 0x579f0
leaq 0x78(%rsp), %rsi
movq %rbp, %rdi
callq 0x562f0
movq %rax, %rbp
movzwl 0x38(%r12), %eax
movq 0xa7e5e(%rip), %rcx     # 0x16c448
cmpw (%rcx), %ax
leaq 0x4fe75(%rip), %rsi     # 0x114469
cmovlq %rbx, %rsi
leaq 0x60(%rsp), %rdi
callq 0x579f0
leaq 0x60(%rsp), %rsi
movq %rbp, %rdi
callq 0x562f0
movq %rax, %rbp
movq %r14, %rbx
movswl %r13w, %eax
cvtsi2sd %eax, %xmm0
movswl 0xa(%r12), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
divsd 0x2febd(%rip), %xmm1    # 0xf44f0
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x30149(%rip), %rcx     # 0xf4790
addsd (%rcx,%rax,8), %xmm1
cvttsd2si %xmm1, %rsi
leaq 0x48(%rsp), %rdi
callq 0x56cf0
leaq 0x48(%rsp), %rsi
movq %rbp, %rdi
callq 0x562f0
movq 0x40(%rsp), %r14
movq %rax, %rdi
callq 0x585e0
movq %rax, %rdi
callq 0x553b0
movq %rax, %r12
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
leaq 0x78(%rsp), %rdi
callq 0x59200
leaq 0x28(%rsp), %rdi
callq 0x59200
leaq 0x10(%rsp), %rdi
callq 0x59200
cmpl $0x0, 0xc(%rsp)
jle 0xc46dd
leaq 0x4ea66(%rip), %rsi     # 0x113126
leaq 0x90(%rsp), %rdi
callq 0x57940
movq %r15, %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x550c0
movq %r15, %rdi
movq %r12, %rsi
callq 0x560e0
movq %r12, %rdi
callq 0x58670
xorl %eax, %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x28(%rsp), %rdx
movl %eax, (%rdx)
movq %r15, %rdi
callq 0x56820
movq %r15, %rdi
callq 0x584a0
movq %r14, %rdi
callq 0x58b80
movq %rbx, %rdi
callq 0x57630
movl 0x10(%rsp), %r14d
movl 0x28(%rsp), %ebx
addl $-0x2, %ebx
leaq 0x90(%rsp), %rdi
callq 0x59200
shlq $0x20, %rbx
orq %r14, %rbx
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc4757
movq %rax, %rbx
jmp 0xc4797
jmp 0xc475e
movq %rax, %rbx
jmp 0xc47a1
jmp 0xc4765
movq %rax, %rbx
jmp 0xc47ab
movq %rax, %rbx
jmp 0xc47b5
jmp 0xc47c3
jmp 0xc47c3
jmp 0xc47c3
jmp 0xc47c3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x57b20
jmp 0xc47c6
jmp 0xc47c3
jmp 0xc47c3
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x60(%rsp), %rdi
callq 0x59200
leaq 0x78(%rsp), %rdi
callq 0x59200
leaq 0x28(%rsp), %rdi
callq 0x59200
leaq 0x10(%rsp), %rdi
callq 0x59200
jmp 0xc47c6
jmp 0xc47c3
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090
nop