// File: /workspace/github_c_makefile_star2_O2/michaelforney[P]wld/font.c
// Function: wld_font_open_pattern
wld_font *
wld_font_open_pattern(struct wld_font_context *context, FcPattern *match)
{
	char *filename;
	struct font *font;
	FcResult result;
	double pixel_size, aspect;

	font = malloc(sizeof *font);

	if (!font)
		goto error0;

	font->context = context;

	result = FcPatternGetString(match, FC_FILE, 0, (FcChar8 **)&filename);

	if (result == FcResultMatch) {
		FT_Error error;

		DEBUG("Loading font file: %s\n", filename);

		error = FT_New_Face(context->library, filename, 0, &font->face);

		if (error == 0)
			goto load_face;
	}

	result = FcPatternGetFTFace(match, FC_FT_FACE, 0, &font->face);

	if (result != FcResultMatch) {
		DEBUG("Couldn't determine font filename or FreeType face\n");
		goto error1;
	}

load_face:
	result = FcPatternGetDouble(match, FC_PIXEL_SIZE, 0, &pixel_size);

	result = FcPatternGetDouble(match, FC_ASPECT, 0, &aspect);

	if (result == FcResultNoMatch)
		aspect = 1.0;

	if (font->face->face_flags & FT_FACE_FLAG_SCALABLE) {
		FT_F26Dot6 width, height;

		width = ((unsigned int)pixel_size) << 6;
		height = ((unsigned int)(pixel_size * aspect)) << 6;

		FT_Set_Char_Size(font->face, width, height, 0, 0);
	} else {
		FT_Set_Pixel_Sizes(font->face, (unsigned int)pixel_size,
		                   (unsigned int)(pixel_size * aspect));
	}

	font->base.ascent = font->face->size->metrics.ascender >> 6;
	font->base.descent = -font->face->size->metrics.descender >> 6;
	font->base.height = font->base.ascent + font->base.descent;
	font->base.max_advance = font->face->size->metrics.max_advance >> 6;

	font->glyphs = calloc(font->face->num_glyphs, sizeof(struct glyph *));

	return &font->base;

error1:
	free(font);
error0:
	return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
movq %rsi, %r14
movq %rdi, %r15
pushq $0x28
popq %rdi
callq 0x9570
testq %rax, %rax
je 0xa15c
movq %rax, %rbx
movq %r15, 0x10(%rax)
leaq 0x6ba9(%rip), %rsi      # 0x10b9d
leaq 0x10(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9690
testl %eax, %eax
je 0xa0f1
movq %rbx, %rcx
addq $0x18, %rcx
leaq 0x6bbc(%rip), %rsi      # 0x10bd5
movq %r14, %rdi
xorl %edx, %edx
callq 0x95b0
testl %eax, %eax
jne 0xa135
leaq 0x6be3(%rip), %rsi      # 0x10c15
leaq 0x18(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9090
leaq 0x6bd7(%rip), %rsi      # 0x10c1f
leaq 0x8(%rsp), %rcx
movq %r14, %rdi
xorl %edx, %edx
callq 0x9090
cmpl $0x1, %eax
jne 0xa06b
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x8(%rsp)
movq 0x18(%rbx), %rdi
testb $0x1, 0x10(%rdi)
movsd 0x18(%rsp), %xmm0
cvttsd2si %xmm0, %rsi
jne 0xa092
mulsd 0x8(%rsp), %xmm0
cvttsd2si %xmm0, %rdx
callq 0x9100
jmp 0xa0ad
mulsd 0x8(%rsp), %xmm0
shll $0x6, %esi
cvttsd2si %xmm0, %rdx
shll $0x6, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x9820
movq 0x18(%rbx), %rax
movq 0xa0(%rax), %rcx
movq 0x30(%rcx), %rdx
shrq $0x6, %rdx
movl %edx, (%rbx)
xorl %esi, %esi
subq 0x38(%rcx), %rsi
shrq $0x6, %rsi
movl %esi, 0x4(%rbx)
addl %edx, %esi
movl %esi, 0x8(%rbx)
movq 0x48(%rcx), %rcx
shrq $0x6, %rcx
movl %ecx, 0xc(%rbx)
movq 0x20(%rax), %rdi
pushq $0x8
popq %rsi
callq 0x9440
movq %rax, 0x20(%rbx)
jmp 0xa15e
movq 0xeef8(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
movq 0x10(%rsp), %rcx
leaq 0x6a9b(%rip), %rsi      # 0x10ba2
leaq 0x6ab1(%rip), %rdx      # 0x10bbf
xorl %eax, %eax
callq 0x9480
movq (%r15), %rdi
movq 0x10(%rsp), %rsi
leaq 0x18(%rbx), %rcx
xorl %edx, %edx
callq 0x9310
testl %eax, %eax
jne 0xa00b
jmp 0xa02b
movq 0xeeb4(%rip), %rax      # 0x18ff0
movq (%rax), %rdi
leaq 0x6a96(%rip), %rsi      # 0x10bdc
leaq 0x6a72(%rip), %rdx      # 0x10bbf
xorl %eax, %eax
callq 0x9480
movq %rbx, %rdi
callq 0x9060
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq