// File: /workspace/github_c_makefile_star2_O1/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 0xc6969
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 0xc696b
testb %bpl, %bpl
je 0xc6259
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 0x60f0e
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 0x63296
movq %rax, %r14
movq %rdx, %r13
leaq 0x70(%rsp), %rdi
callq 0x582a0
leaq 0xf0(%rsp), %rdi
movq %rax, %rsi
callq 0x570b0
leaq 0x63141(%rip), %rsi     # 0x1293f0
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 0xa6c79(%rip), %rcx     # 0x16cf58
testw %ax, (%rcx)
leaq 0x4c59b(%rip), %r15     # 0x112884
leaq 0x4e171(%rip), %rsi     # 0x114461
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 0xa6129(%rip), %rcx     # 0x16c448
cmpw (%rcx), %ax
leaq 0x4e140(%rip), %rsi     # 0x114469
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 0x62f4e
movswl %bp, %ecx
imull %ecx, %eax
cvtsi2sd %eax, %xmm0
divsd 0x2e173(%rip), %xmm0    # 0xf44f0
xorpd %xmm1, %xmm1
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
leaq 0x2e3ff(%rip), %rcx     # 0xf4790
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 0xc641f
movq $0x0, 0x10(%rsp)
jmp 0xc6519
callq 0xc508a
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 0x2dea0(%rip), %xmm0    # 0xf4368
movzbl %bh, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x2de8e(%rip), %xmm3    # 0xf4368
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 0x2ddaa(%rip), %xmm0    # 0xf4368
movzbl %bh, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
movsd 0x2dd98(%rip), %xmm3    # 0xf4368
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 0x4c267(%rip), %rsi     # 0x112883
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
xorl %eax, %eax
cmpl $0x2, 0xf8(%rsp)
jl 0xc6665
movq 0xa6760(%rip), %rsi     # 0x16cdb8
leaq 0x70(%rsp), %rdi
callq 0x57680
addl $0x3, %eax
movl %eax, 0x44(%rsp)
cmpl $0x0, 0xf8(%rsp)
jle 0xc6913
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
incl %r12d
leaq 0xf0(%rsp), %rdi
movl %r12d, %esi
callq 0x64224
movq %rax, %r14
movq %rax, %rdi
callq 0x57180
testl %eax, %eax
je 0xc68f6
movq 0x60(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x63296
movq %rax, 0x38(%rsp)
movq %rdx, %rbp
movq 0x60(%rsp), %rdi
callq 0x632d8
testb %al, %al
je 0xc66dc
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x56730
subl %eax, %ebp
jmp 0xc66e1
movq 0x38(%rsp), %rbp
movq %r14, %rdi
xorl %esi, %esi
callq 0x56bd0
xorl %r13d, %r13d
testb %al, %al
je 0xc670c
movq %r14, %rdi
leaq 0x4ca2a(%rip), %rsi     # 0x113126
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 0xa626f(%rip), %rcx     # 0x16c998
testw %ax, (%rcx)
setne %dil
callq 0x56200
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x58850
xorl %edi, %edi
movq 0xa64c5(%rip), %rcx     # 0x16cc10
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 0xc683f
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 0x62c30(%rip), %rsi     # 0x1293f0
callq 0x579f0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x562f0
movq %rax, %rdi
leaq 0x4c94a(%rip), %rsi     # 0x113126
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 0x62b86(%rip), %rsi     # 0x1293f0
callq 0x579f0
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
callq 0x562f0
movq %rax, %rdi
leaq 0x4c8a0(%rip), %rsi     # 0x113126
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 0xc667d
movq (%rsp), %rbx
cmpw $0x0, 0xa(%rbx)
jne 0xc693c
movq 0x10(%rsp), %rdi
callq 0x584a0
movq 0xc0(%rbx), %rdi
callq 0x57ab0
movq %rbx, %rdi
callq 0xc50e0
movq 0x18(%rsp), %rdi
callq 0x584a0
movq 0xd0(%rbx), %rdi
callq 0x57ab0
leaq 0xf0(%rsp), %rdi
callq 0x63e08
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 0xc69e2
jmp 0xc69ef
jmp 0xc69b6
jmp 0xc6996
jmp 0xc699b
movq %rax, %rbx
jmp 0xc69da
jmp 0xc69ef
movq %rax, %rbx
jmp 0xc69c6
movq %rax, %rbx
jmp 0xc69d0
jmp 0xc69ef
jmp 0xc69ef
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x59200
jmp 0xc69b9
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 0xc6a32
jmp 0xc6a22
jmp 0xc69f4
jmp 0xc6a22
movq %rax, %rbx
jmp 0xc6a32
movq %rax, %rbx
jmp 0xc6a16
jmp 0xc6a22
jmp 0xc6a22
jmp 0xc6a09
jmp 0xc6a22
jmp 0xc6a22
jmp 0xc6a22
jmp 0xc6a22
jmp 0xc6a22
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x59200
leaq 0x20(%rsp), %rdi
callq 0x59200
jmp 0xc6a25
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x63e08
leaq 0x70(%rsp), %rdi
callq 0x56720
movq %rbx, %rdi
callq 0x57090