// File: /workspace/github_c_makefile_star2_O3/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 0xc59cc
movl %r8d, %ebp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rsi, %rdi
xorl %esi, %esi
callq 0x55260
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
jne 0xc59ce
testb %bpl, %bpl
je 0xc52b9
movq (%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movl $0x1, %r8d
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x60f64
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x55b70
movupd (%rbx), %xmm0
leaq 0xb0(%rsp), %rsi
movapd %xmm0, (%rsi)
movq (%rsp), %rax
leaq 0x28(%rax), %rdi
movq %rdi, 0x60(%rsp)
callq 0x632ca
movq %rax, %r14
movq %rdx, %r13
leaq 0x70(%rsp), %rdi
callq 0x582a0
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x63301(%rip), %rsi     # 0x128610
leaq 0x20(%rsp), %rdi
callq 0x579f0
leaq 0xf0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x562f0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x58850
movq 0xa6c19(%rip), %rcx     # 0x16bf58
testw %ax, (%rcx)
leaq 0x4c6df(%rip), %r15     # 0x111a28
leaq 0x4e31d(%rip), %rsi     # 0x11366d
cmoveq %r15, %rsi
leaq 0x48(%rsp), %rdi
callq 0x579f0
leaq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x562f0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x56be0
movq 0xa60c9(%rip), %rcx     # 0x16b448
cmpw (%rcx), %ax
leaq 0x4e2ec(%rip), %rsi     # 0x113675
cmovlq %r15, %rsi
leaq 0xd8(%rsp), %rdi
callq 0x579f0
leaq 0xd8(%rsp), %rsi
movq %rbx, %rdi
callq 0x562f0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x58d40
movl %eax, %ebp
movq (%rsp), %rax
leaq 0x24(%rax), %rdi
movl $0x60, %esi
callq 0x62fd6
movswl %bp, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
divsd 0x2e2db(%rip), %xmm0    # 0xf36b8
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x30747(%rip), %rcx     # 0xf5b38
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rsi
leaq 0xc0(%rsp), %rdi
callq 0x56cf0
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x562f0
movq %rax, %rdi
callq 0x585e0
movq %rax, %rdi
callq 0x553b0
movq %rax, %r15
leaq 0xc0(%rsp), %rdi
callq 0x59200
leaq 0xd8(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
leaq 0xf0(%rsp), %rdi
callq 0x59200
movq (%rsp), %rdi
cmpw $0x0, 0xa(%rdi)
je 0xc547f
movq $0x0, 0x10(%rsp)
jmp 0xc5579
callq 0xc3f18
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x56e50
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq %r14, %rax
shrq $0x20, %rax
xorps %xmm1, %xmm1
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 0x565a0
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x57b50
movq (%rsp), %rax
movq 0xc0(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x57550
movzbl 0x8(%rax), %ebp
leaq 0x70(%rsp), %rdi
callq 0x57550
movq 0x8(%rax), %rbx
leaq 0x70(%rsp), %rdi
callq 0x57550
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd 0x2de40(%rip), %xmm0    # 0xf3368
movzbl %bh, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x2de2e(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm1
movzbl 0xa(%rax), %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
movq 0x8(%rsp), %rdi
callq 0x58030
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
callq 0x586d0
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x560e0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
callq 0x56e50
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movq %r14, %rax
shrq $0x20, %rax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movl %r13d, %ecx
subl %r14d, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
shrq $0x20, %r13
subl %eax, %r13d
incl %r13d
xorps %xmm3, %xmm3
cvtsi2sd %r13d, %xmm3
callq 0x565a0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
callq 0x57b50
movq (%rsp), %rax
movq 0xd0(%rax), %r14
leaq 0x70(%rsp), %rdi
callq 0x57550
movzbl 0x8(%rax), %ebp
leaq 0x70(%rsp), %rdi
callq 0x57550
movq 0x8(%rax), %rbx
leaq 0x70(%rsp), %rdi
callq 0x57550
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd 0x2dd4a(%rip), %xmm0    # 0xf3368
movzbl %bh, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x2dd38(%rip), %xmm3    # 0xf3368
divsd %xmm3, %xmm1
movzbl 0xa(%rax), %eax
xorps %xmm2, %xmm2
cvtsi2sd %eax, %xmm2
divsd %xmm3, %xmm2
movq %r14, %rdi
callq 0x58030
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
callq 0x586d0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x560e0
movq %r15, %rdi
callq 0x58670
leaq 0x4c3ab(%rip), %rsi     # 0x111a27
leaq 0x20(%rsp), %rdi
callq 0x579f0
leaq 0xf0(%rsp), %rdi
leaq 0x20(%rsp), %rdx
movq %r12, %rsi
callq 0x57f10
leaq 0x20(%rsp), %rdi
callq 0x59200
movl 0xf8(%rsp), %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
jl 0xc56ce
movq 0xa66fe(%rip), %rsi     # 0x16bdb8
leaq 0x70(%rsp), %rdi
callq 0x57680
addl $0x3, %eax
movl 0xf8(%rsp), %ecx
movl %eax, 0x44(%rsp)
testl %ecx, %ecx
jle 0xc5976
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
leaq 0xf0(%rsp), %rdi
movl %r12d, %esi
callq 0x64250
movq %rax, %r14
movq %rax, %rdi
callq 0x57180
testl %eax, %eax
je 0xc5959
movq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x632ca
movq %rax, 0x38(%rsp)
movq %rdx, %rbp
movq 0x60(%rsp), %rdi
callq 0x6330c
testb %al, %al
je 0xc573f
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x56730
subl %eax, %ebp
jmp 0xc5744
movq 0x38(%rsp), %rbp
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
xorl %r13d, %r13d
testb %al, %al
je 0xc576f
movq %r14, %rdi
leaq 0x4cb77(%rip), %rsi     # 0x1122d6
callq 0x57940
movq %rax, %rdi
callq 0x56370
movq %rax, %r13
callq 0x58890
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x58850
xorl %edi, %edi
movq 0xa620c(%rip), %rcx     # 0x16b998
testw %ax, (%rcx)
setne %dil
callq 0x56200
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x58850
xorl %edi, %edi
movq 0xa6462(%rip), %rcx     # 0x16bc10
testw %ax, (%rcx)
setne %dil
callq 0x56f00
movq %rax, %r15
movl %r13d, 0xc(%rbx)
movl %r13d, 0xc(%rax)
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x58ac0
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x58ac0
movq (%rsp), %rax
cmpw $0x0, 0xa(%rax)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x68(%rsp)
jne 0xc58a2
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x561b0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x62ded(%rip), %rsi     # 0x128610
callq 0x579f0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x562f0
movq %rax, %rdi
leaq 0x4ca97(%rip), %rsi     # 0x1122d6
callq 0x57940
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x550c0
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
movq 0x38(%rsp), %rax
shrq $0x20, %rax
cvtsi2sd %eax, %xmm1
movsd 0x68(%rsp), %xmm0
callq 0x572e0
movq (%rsp), %rax
movq 0xc0(%rax), %rdi
movq 0x10(%rsp), %rsi
callq 0x57830
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x561b0
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x570b0
leaq 0x48(%rsp), %rbx
movq %rbx, %rdi
leaq 0x62d43(%rip), %rsi     # 0x128610
callq 0x579f0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x562f0
movq %rax, %rdi
leaq 0x4c9ed(%rip), %rsi     # 0x1122d6
callq 0x57940
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x550c0
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
movq 0x38(%rsp), %rax
shrq $0x20, %rax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x68(%rsp), %xmm0
callq 0x572e0
movq (%rsp), %rax
movq 0xd0(%rax), %rdi
movq 0x18(%rsp), %rsi
callq 0x57830
movq 0x8(%rsp), %rdi
callq 0x58540
movl 0x44(%rsp), %eax
addl %eax, 0xb4(%rsp)
movl 0xf8(%rsp), %eax
decl %eax
cmpl %eax, %r12d
jl 0xc56e0
movq (%rsp), %rbx
cmpw $0x0, 0xa(%rbx)
jne 0xc599f
movq 0x10(%rsp), %rdi
callq 0x584a0
movq 0xc0(%rbx), %rdi
callq 0x57ab0
movq %rbx, %rdi
callq 0xc3f6e
movq 0x18(%rsp), %rdi
callq 0x584a0
movq 0xd0(%rbx), %rdi
callq 0x57ab0
leaq 0xf0(%rsp), %rdi
callq 0x63e3c
leaq 0x70(%rsp), %rdi
callq 0x56720
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 0xc5a45
jmp 0xc5a52
jmp 0xc5a19
jmp 0xc59f9
jmp 0xc59fe
movq %rax, %rbx
jmp 0xc5a3d
jmp 0xc5a52
movq %rax, %rbx
jmp 0xc5a29
movq %rax, %rbx
jmp 0xc5a33
jmp 0xc5a52
jmp 0xc5a52
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x59200
jmp 0xc5a1c
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x59200
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
leaq 0xf0(%rsp), %rdi
callq 0x59200
jmp 0xc5a95
jmp 0xc5a85
jmp 0xc5a57
jmp 0xc5a85
movq %rax, %rbx
jmp 0xc5a95
movq %rax, %rbx
jmp 0xc5a79
jmp 0xc5a85
jmp 0xc5a85
jmp 0xc5a6c
jmp 0xc5a85
jmp 0xc5a85
jmp 0xc5a85
jmp 0xc5a85
jmp 0xc5a85
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0xc5a88
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x63e3c
leaq 0x70(%rsp), %rdi
callq 0x56720
movq %rbx, %rdi
callq 0x57090
nop