// File: /workspace/github_c_makefile_star2_O3/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 0xc35c4
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 0x65207(%rip), %rsi     # 0x128610
leaq 0x28(%rsp), %rdi
callq 0x579f0
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x562f0
movq %rax, %rbp
movq 0xa8b2c(%rip), %rax     # 0x16bf58
movzwl (%rax), %eax
testw %ax, 0x3a(%r12)
leaq 0x4e5ec(%rip), %rbx     # 0x111a28
leaq 0x5022a(%rip), %rsi     # 0x11366d
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 0xa7fda(%rip), %rcx     # 0x16b448
cmpw (%rcx), %ax
leaq 0x501fd(%rip), %rsi     # 0x113675
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 0x30201(%rip), %xmm1    # 0xf36b8
xorpd %xmm0, %xmm0
xorl %eax, %eax
ucomisd %xmm1, %xmm0
seta %al
leaq 0x3266d(%rip), %rcx     # 0xf5b38
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 0xc3561
leaq 0x4ed92(%rip), %rsi     # 0x1122d6
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 0xc35db
movq %rax, %rbx
jmp 0xc361b
jmp 0xc35e2
movq %rax, %rbx
jmp 0xc3625
jmp 0xc35e9
movq %rax, %rbx
jmp 0xc362f
movq %rax, %rbx
jmp 0xc3639
jmp 0xc3647
jmp 0xc3647
jmp 0xc3647
jmp 0xc3647
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x57b20
jmp 0xc364a
jmp 0xc3647
jmp 0xc3647
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 0xc364a
jmp 0xc3647
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090
nop