// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/graphics/backends/cairo/surfacecairo.cpp
// Function: smooth::GUI::SurfaceCairo::SetText(smooth::String const&, smooth::GUI::Rect const&, smooth::GUI::Font const&, bool)
S::Int S::GUI::SurfaceCairo::SetText(const String &string, const Rect &iRect, const Font &iFont, Bool shadow)
{
	if (window == NIL) return Success();

	if (string == NIL) return Error();
	if (shadow)	   return SurfaceBackend::SetText(string, iRect, iFont, shadow);

	Font	 font	      = iFont;
	Rect	 rect	      = iRect;
	Int	 lineHeight   = 0;

	/* Set up Cairo font.
	 */
	Rect	 tRect = rightToLeft.TranslateRect(rect);

	PangoLayout		*layout = NIL;
	PangoFontDescription	*desc	= pango_font_description_from_string(String(font.GetName())
									    .Append(" ")
									    .Append(font.GetStyle() & Font::Italic ? "Italic " : "")
									    .Append(font.GetWeight() >= Font::Bold ? "Bold " : "")
									    .Append(String::FromInt(Math::Round(font.GetSize() * fontSize.TranslateY(96) / 96.0))));

	if (!painting)
	{
		CreateCairoContext();

		cairo_save(context);
		cairo_rectangle(context, tRect.left, tRect.top, tRect.GetWidth(), tRect.GetHeight() + 1);
		cairo_clip(context);

		cairo_set_source_rgb(context, font.GetColor().GetRed() / 255.0, font.GetColor().GetGreen() / 255.0, font.GetColor().GetBlue() / 255.0);

		layout = pango_cairo_create_layout(context);

		pango_layout_set_font_description(layout, desc);
	}

	cairo_save(paintContextCairo);
	cairo_rectangle(paintContextCairo, tRect.left, tRect.top, tRect.GetWidth(), tRect.GetHeight() + 1);
	cairo_clip(paintContextCairo);

	cairo_set_source_rgb(paintContextCairo, font.GetColor().GetRed() / 255.0, font.GetColor().GetGreen() / 255.0, font.GetColor().GetBlue() / 255.0);

	PangoLayout	*paintLayout = pango_cairo_create_layout(paintContextCairo);

	pango_layout_set_font_description(paintLayout, desc);
	pango_font_description_free(desc);

	/* Draw text line by line.
	 */
	const Array<String>	&lines = string.Explode("\n");

	if (lines.Length() > 1) lineHeight = font.GetScaledTextSizeY() + 3;

	foreach (const String &line, lines)
	{
		Int	 lineLength = line.Length();

		if (lineLength == 0) { rect.top += lineHeight; continue; }

		Rect	 tRect = rightToLeft.TranslateRect(rect);

		tRect.left = rightToLeft.GetRightToLeft() ? tRect.right - font.GetScaledTextSizeX(line) : tRect.left;

		Int	 utf8Length = (line != NIL ? strlen(line.ConvertTo("UTF-8")) : 0);

		PangoAttrList	*attributes    = pango_attr_list_new();
		PangoAttribute	*underline     = pango_attr_underline_new(font.GetStyle() & Font::Underline ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE);
		PangoAttribute	*strikethrough = pango_attr_strikethrough_new(font.GetStyle() & Font::StrikeOut ? True : False);

		underline->end_index	 = utf8Length;
		strikethrough->end_index = utf8Length;

		pango_attr_list_insert(attributes, underline);
		pango_attr_list_insert(attributes, strikethrough);

		if (!painting)
		{
			pango_layout_set_attributes(layout, attributes);

			pango_layout_set_text(layout, String(line).Append(" ").ConvertTo("UTF-8"), -1);

			cairo_move_to(context, tRect.left, tRect.top);
			pango_cairo_show_layout(context, layout);
		}

		pango_layout_set_attributes(paintLayout, attributes);

		pango_layout_set_text(paintLayout, String(line).Append(" ").ConvertTo("UTF-8"), -1);

		cairo_move_to(paintContextCairo, tRect.left, tRect.top);
		pango_cairo_show_layout(paintContextCairo, paintLayout);

		pango_attr_list_unref(attributes);

		rect.top += lineHeight;
	}

	if (!painting)
	{
		g_object_unref(layout);

		cairo_restore(context);

		DestroyCairoContext();
	}

	g_object_unref(paintLayout);

	cairo_restore(paintContextCairo);

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, (%rsp)
cmpq $0x0, 0x50(%rdi)
je 0xbf5ff
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rsi, %rdi
xorl %esi, %esi
callq 0x56280
testb %al, %al
je 0xbeefa
pushq $-0x1
popq %rax
jmp 0xbf601
testb %bpl, %bpl
je 0xbef26
pushq $0x1
popq %r8
movq (%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x61c9c
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x56bf0
movupd (%rbx), %xmm0
leaq 0xb0(%rsp), %rsi
movapd %xmm0, (%rsi)
movq (%rsp), %rax
leaq 0x28(%rax), %rdi
movq %rdi, 0x60(%rsp)
callq 0x63e10
movq %rax, %r14
movq %rdx, %r13
leaq 0x70(%rsp), %rdi
callq 0x59550
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x58280
leaq 0x59514(%rip), %rsi     # 0x118490
leaq 0x20(%rsp), %rdi
callq 0x58c40
leaq 0xf0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x573e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x59b70
movq 0xa2fac(%rip), %rcx     # 0x161f58
testw %ax, (%rcx)
leaq 0x42972(%rip), %r15     # 0x101928
leaq 0x44590(%rip), %rsi     # 0x10354d
cmoveq %r15, %rsi
leaq 0x48(%rsp), %rdi
callq 0x58c40
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x573e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x57d50
movq 0xa245c(%rip), %rcx     # 0x161448
cmpw (%rcx), %ax
leaq 0x4455f(%rip), %rsi     # 0x103555
cmovlq %r15, %rsi
leaq 0xd8(%rsp), %rdi
callq 0x58c40
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x573e0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5a090
movl %eax, %ebp
movq (%rsp), %rax
leaq 0x24(%rax), %rdi
pushq $0x60
popq %rsi
callq 0x63bca
movswl %bp, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
divsd 0x244c8(%rip), %xmm0    # 0xe3510
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x24914(%rip), %rcx     # 0xe3970
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x57e80
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x573e0
movq %rax, %rdi
callq 0x598d0
movq %rax, %rdi
callq 0x563f0
movq %rax, %r15
leaq 0xc0(%rsp), %rdi
callq 0x5a588
leaq 0xd8(%rsp), %rdi
callq 0x5a588
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x5a588
leaq 0xf0(%rsp), %rdi
callq 0x5a588
movq (%rsp), %rdi
cmpw $0x0, 0xa(%rdi)
je 0xbf0ea
movq $0x0, 0x8(%rsp)
jmp 0xbf1d5
callq 0xbdda4
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x58000
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
cvtsi2sd %r14d, %xmm0
movq %r14, %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movl %r13d, %ecx
subl %r14d, %ecx
cvtsi2sd %ecx, %xmm2
movq %r13, %rcx
shrq $0x20, %rcx
subl %eax, %ecx
incl %ecx
cvtsi2sd %ecx, %xmm3
callq 0x576b0
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x58dc0
movq (%rsp), %rax
movq 0xc0(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x58750
movzbl 0x8(%rax), %ebp
leaq 0x70(%rsp), %rdi
callq 0x58750
movq 0x8(%rax), %rbx
leaq 0x70(%rsp), %rdi
callq 0x58750
cvtsi2sd %ebp, %xmm0
divsd 0x241c6(%rip), %xmm0    # 0xe3350
movzbl %bh, %ecx
cvtsi2sd %ecx, %xmm1
movsd 0x241b7(%rip), %xmm3    # 0xe3350
divsd %xmm3, %xmm1
movzbl 0xa(%rax), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
movq 0x40(%rsp), %rdi
callq 0x592c0
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x599c0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x571c0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
callq 0x58000
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
cvtsi2sd %r14d, %xmm0
movq %r14, %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movl %r13d, %ecx
subl %r14d, %ecx
cvtsi2sd %ecx, %xmm2
shrq $0x20, %r13
subl %eax, %r13d
incl %r13d
cvtsi2sd %r13d, %xmm3
callq 0x576b0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
callq 0x58dc0
movq (%rsp), %rax
movq 0xd0(%rax), %r14
leaq 0x70(%rsp), %rdi
callq 0x58750
movzbl 0x8(%rax), %ebp
leaq 0x70(%rsp), %rdi
callq 0x58750
movq 0x8(%rax), %rbx
leaq 0x70(%rsp), %rdi
callq 0x58750
cvtsi2sd %ebp, %xmm0
divsd 0x240e5(%rip), %xmm0    # 0xe3350
movzbl %bh, %ecx
cvtsi2sd %ecx, %xmm1
movsd 0x240d6(%rip), %xmm3    # 0xe3350
divsd %xmm3, %xmm1
movzbl 0xa(%rax), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
movq %r14, %rdi
callq 0x592c0
movq (%rsp), %rbx
movq 0xd0(%rbx), %rdi
callq 0x599c0
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x571c0
movq %r15, %rdi
callq 0x59960
leaq 0x42664(%rip), %rsi     # 0x101927
leaq 0x20(%rsp), %rdi
callq 0x58c40
leaq 0xf0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r12, %rsi
callq 0x591a0
leaq 0x20(%rsp), %rdi
callq 0x5a588
cmpl $0x2, 0xf8(%rsp)
movl $0x0, 0x1c(%rsp)
jl 0xbf316
movq 0xa2ab3(%rip), %rsi     # 0x161db8
leaq 0x70(%rsp), %rdi
callq 0x588a0
addl $0x3, %eax
movl %eax, 0x1c(%rsp)
xorl %esi, %esi
leal -0x1(%rsi), %eax
movl 0xf8(%rsp), %ecx
decl %ecx
cmpl %ecx, %eax
jge 0xbf5ad
leaq 0xf0(%rsp), %rdi
movq %rsi, 0x40(%rsp)
callq 0x64d9c
movq %rax, %rbx
movq %rax, %rdi
callq 0x58370
testl %eax, %eax
je 0xbf592
movq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x63e10
movq %rax, 0x38(%rsp)
movq %rdx, %rbp
movq 0x60(%rsp), %rdi
callq 0x63e62
testb %al, %al
je 0xbf38a
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x57870
subl %eax, %ebp
jmp 0xbf38f
movq 0x38(%rsp), %rbp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x57d40
xorl %r13d, %r13d
testb %al, %al
je 0xbf3ba
movq %rbx, %rdi
leaq 0x42e1c(%rip), %rsi     # 0x1021c6
callq 0x58b90
movq %rax, %rdi
callq 0x57460
movq %rax, %r13
callq 0x59bc0
movq %rax, %r14
leaq 0x70(%rsp), %rdi
callq 0x59b70
xorl %edi, %edi
movq 0xa25c3(%rip), %rcx     # 0x161998
testw %ax, (%rcx)
setne %dil
callq 0x572f0
movq %rax, %r12
leaq 0x70(%rsp), %rdi
callq 0x59b70
xorl %edi, %edi
movq 0xa2819(%rip), %rcx     # 0x161c10
testw %ax, (%rcx)
setne %dil
callq 0x580b0
movq %rax, %r15
movl %r13d, 0xc(%r12)
movl %r13d, 0xc(%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x59e00
movq %r14, %rdi
movq %r15, %rsi
callq 0x59e00
movq (%rsp), %rax
cmpw $0x0, 0xa(%rax)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x68(%rsp)
jne 0xbf4e4
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x572a0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x58280
leaq 0x48(%rsp), %r15
movq %r15, %rdi
leaq 0x59029(%rip), %rsi     # 0x118490
callq 0x58c40
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0x573e0
movq %rax, %rdi
leaq 0x42d43(%rip), %rsi     # 0x1021c6
callq 0x58b90
movq 0x8(%rsp), %rdi
movq %rax, %rsi
pushq $-0x1
popq %rdx
callq 0x560c0
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x5a588
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
movq 0x38(%rsp), %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movsd 0x68(%rsp), %xmm0
callq 0x584d0
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
movq 0x8(%rsp), %rsi
callq 0x58a70
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x572a0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x58280
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x58f83(%rip), %rsi     # 0x118490
callq 0x58c40
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x573e0
movq %rax, %rdi
leaq 0x42c9d(%rip), %rsi     # 0x1021c6
callq 0x58b90
movq 0x10(%rsp), %rdi
movq %rax, %rsi
pushq $-0x1
popq %rdx
callq 0x560c0
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x5a588
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
movq 0x38(%rsp), %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movsd 0x68(%rsp), %xmm0
callq 0x584d0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
movq 0x10(%rsp), %rsi
callq 0x58a70
movq %r14, %rdi
callq 0x59830
movl 0x1c(%rsp), %eax
addl %eax, 0xb4(%rsp)
movq 0x40(%rsp), %rsi
incl %esi
movq (%rsp), %rbx
jmp 0xbf318
cmpw $0x0, 0xa(%rbx)
jne 0xbf5d2
movq 0x8(%rsp), %rdi
callq 0x59790
movq 0xc0(%rbx), %rdi
callq 0x58d10
movq %rbx, %rdi
callq 0xbddf8
movq 0x10(%rsp), %rdi
callq 0x59790
movq 0xd0(%rbx), %rdi
callq 0x58d10
leaq 0xf0(%rsp), %rdi
callq 0x64988
leaq 0x70(%rsp), %rdi
callq 0x57860
xorl %eax, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
jmp 0xbf678
jmp 0xbf685
jmp 0xbf64c
jmp 0xbf62c
jmp 0xbf631
movq %rax, %rbx
jmp 0xbf670
jmp 0xbf685
movq %rax, %rbx
jmp 0xbf65c
movq %rax, %rbx
jmp 0xbf666
jmp 0xbf685
jmp 0xbf685
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x5a588
jmp 0xbf64f
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x5a588
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x5a588
leaq 0xf0(%rsp), %rdi
callq 0x5a588
jmp 0xbf6c8
jmp 0xbf6b8
jmp 0xbf6b8
jmp 0xbf68a
movq %rax, %rbx
jmp 0xbf6c8
movq %rax, %rbx
jmp 0xbf6ac
jmp 0xbf6b8
jmp 0xbf6b8
jmp 0xbf69f
jmp 0xbf6b8
jmp 0xbf6b8
jmp 0xbf6b8
jmp 0xbf6b8
jmp 0xbf6b8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x5a588
jmp 0xbf6bb
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x64988
leaq 0x70(%rsp), %rdi
callq 0x57860
movq %rbx, %rdi
callq 0x58260