 +	char *filename;
 +	fz_font *font;
 +
-+	switch (script)
-+	{
-+	case UCDN_SCRIPT_HANGUL:
-+	case UCDN_SCRIPT_HIRAGANA:
-+	case UCDN_SCRIPT_KATAKANA:
-+	case UCDN_SCRIPT_BOPOMOFO:
-+	case UCDN_SCRIPT_HAN:
-+		filename = get_font_file("noto/NotoSansCJK-Regular.ttf");
-+		font = fz_new_font_from_file(ctx, NULL, filename, 0, 1);
-+		return font;
-+	}
-+
-+	return NULL;
++	filename = get_font_file("noto/NotoSansCJK-Regular.ttf");
++	font = fz_new_font_from_file(ctx, NULL, filename, 0, 1);
++	free(filename);
++	return font;
 +}
 +
 +void

 		const unsigned char *data;
 		int len;
 		int index;
@@ -410,8 +475,15 @@ pdf_load_substitute_cjk_font(fz_context *ctx, pdf_font_desc *fontdesc, const cha
 		if (!data)
 			fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin CJK font");
 
-		/* A glyph bbox cache is too big for CJK fonts. */
 		fontdesc->font = fz_new_font_from_memory(ctx, fontname, data, len, index, 0);
+#else
+		char * filename = fz_lookup_cjk_font_from_file(ctx, ros, serif, fontdesc->wmode);
+		if (!filename)
+			fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find builtin CJK font");
+

 		const unsigned char *data;
 		int size;
 
@@ -23,6 +66,18 @@ fz_load_html_default_font(fz_context *ctx, fz_html_font_set *set, const char *fa
 			fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font: %s", real_family);
 		set->fonts[idx] = fz_new_font_from_memory(ctx, NULL, data, size, 0, 1);
 		fz_font_flags(set->fonts[idx])->is_serif = !is_sans;
+#else
+		char *filename = html_lookup_substitute_font_from_file(ctx, family, is_mono, !is_sans, is_bold, is_italic);
+		if (!filename)
+			fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load html font");
+
+		set->fonts[idx] = fz_new_font_from_file(ctx, NULL, filename, 0, 1);
+		fz_font_flags(set->fonts[idx])->is_mono = is_mono;
+		fz_font_flags(set->fonts[idx])->is_bold = is_bold;
+		fz_font_flags(set->fonts[idx])->is_italic = is_italic;
+		fz_font_flags(set->fonts[idx])->is_serif = !is_sans;
+		free(filename);
+#endif
 	}
 	return set->fonts[idx];
 }
@@ -73,7 +128,7 @@ fz_load_html_font(fz_context *ctx, fz_html_font_set *set, const char *family, in
 		return font;
 	}
 
