aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-09-07 09:52:01 +0800
committerPo Lu2022-09-07 09:52:35 +0800
commit473313d2a85a7ae73daf5cc7c205f6285286eecf (patch)
tree72e0c5e2fac76e2dbe0301d1cec69f6793ce6405 /src
parent976965eb5ed00ddc8806b2adcbd5761189823f2c (diff)
downloademacs-473313d2a85a7ae73daf5cc7c205f6285286eecf.tar.gz
emacs-473313d2a85a7ae73daf5cc7c205f6285286eecf.zip
Fix nsfont breakage since 6b1ed2f2c99a1c2da56c5f434570c438cad6576d
* nsfont.m (ns_spec_to_descriptor): Fix coding style, also handle `monospace' special family. (ns_descriptor_to_entity): Fix reporting of spacing on fonts. (ns_findfonts): Fix coding style.
Diffstat (limited to 'src')
-rw-r--r--src/nsfont.m244
1 files changed, 118 insertions, 126 deletions
diff --git a/src/nsfont.m b/src/nsfont.m
index b54118afe5d..d072b5ce779 100644
--- a/src/nsfont.m
+++ b/src/nsfont.m
@@ -324,106 +324,98 @@ ns_get_family (Lisp_Object font_spec)
324static NSFontDescriptor * 324static NSFontDescriptor *
325ns_spec_to_descriptor (Lisp_Object font_spec) 325ns_spec_to_descriptor (Lisp_Object font_spec)
326{ 326{
327 NSFontDescriptor *fdesc; 327 NSFontDescriptor *fdesc;
328 NSMutableDictionary *fdAttrs = [NSMutableDictionary new]; 328 NSMutableDictionary *fdAttrs = [NSMutableDictionary new];
329 NSString *family = ns_get_family (font_spec); 329 NSString *family = ns_get_family (font_spec);
330 NSMutableDictionary *tdict = [NSMutableDictionary new]; 330 NSMutableDictionary *tdict = [NSMutableDictionary new];
331 331
332 Lisp_Object tem; 332 Lisp_Object tem;
333 333
334 tem = FONT_SLANT_SYMBOLIC (font_spec); 334 tem = FONT_SLANT_SYMBOLIC (font_spec);
335 if (!NILP (tem)) 335 if (!NILP (tem))
336 { 336 {
337 if (EQ (tem, Qitalic) || EQ (tem, Qoblique)) 337 if (EQ (tem, Qitalic) || EQ (tem, Qoblique))
338 [tdict setObject: [NSNumber numberWithFloat: 1.0] 338 [tdict setObject: [NSNumber numberWithFloat: 1.0]
339 forKey: NSFontSlantTrait]; 339 forKey: NSFontSlantTrait];
340 else if (EQ (tem, intern ("reverse-italic")) || 340 else if (EQ (tem, intern ("reverse-italic"))
341 EQ (tem, intern ("reverse-oblique"))) 341 || EQ (tem, intern ("reverse-oblique")))
342 [tdict setObject: [NSNumber numberWithFloat: -1.0] 342 [tdict setObject: [NSNumber numberWithFloat: -1.0]
343 forKey: NSFontSlantTrait]; 343 forKey: NSFontSlantTrait];
344 else 344 else
345 [tdict setObject: [NSNumber numberWithFloat: 0.0] 345 [tdict setObject: [NSNumber numberWithFloat: 0.0]
346 forKey: NSFontSlantTrait]; 346 forKey: NSFontSlantTrait];
347 } 347 }
348 348
349 tem = FONT_WIDTH_SYMBOLIC (font_spec); 349 tem = FONT_WIDTH_SYMBOLIC (font_spec);
350 if (!NILP (tem)) 350 if (!NILP (tem))
351 { 351 {
352 if (EQ (tem, Qcondensed)) 352 if (EQ (tem, Qcondensed))
353 [tdict setObject: [NSNumber numberWithFloat: -1.0] 353 [tdict setObject: [NSNumber numberWithFloat: -1.0]
354 forKey: NSFontWidthTrait]; 354 forKey: NSFontWidthTrait];
355 else if (EQ (tem, Qexpanded)) 355 else if (EQ (tem, Qexpanded))
356 [tdict setObject: [NSNumber numberWithFloat: 1.0] 356 [tdict setObject: [NSNumber numberWithFloat: 1.0]
357 forKey: NSFontWidthTrait]; 357 forKey: NSFontWidthTrait];
358 else 358 else
359 [tdict setObject: [NSNumber numberWithFloat: 0.0] 359 [tdict setObject: [NSNumber numberWithFloat: 0.0]
360 forKey: NSFontWidthTrait]; 360 forKey: NSFontWidthTrait];
361 } 361 }
362 362
363 tem = FONT_WEIGHT_SYMBOLIC (font_spec); 363 tem = FONT_WEIGHT_SYMBOLIC (font_spec);
364 364
365 if (!NILP (tem)) 365 if (!NILP (tem))
366 { 366 {
367 if (EQ (tem, Qbold)) 367 if (EQ (tem, Qbold))
368 { 368 {
369 [tdict setObject: [NSNumber numberWithFloat: 1.0] 369 [tdict setObject: [NSNumber numberWithFloat: 1.0]
370 forKey: NSFontWeightTrait]; 370 forKey: NSFontWeightTrait];
371 } 371 }
372 else if (EQ (tem, Qlight)) 372 else if (EQ (tem, Qlight))
373 { 373 {
374 [tdict setObject: [NSNumber numberWithFloat: -1.0] 374 [tdict setObject: [NSNumber numberWithFloat: -1.0]
375 forKey: NSFontWeightTrait]; 375 forKey: NSFontWeightTrait];
376 } 376 }
377 else 377 else
378 { 378 {
379 [tdict setObject: [NSNumber numberWithFloat: 0.0] 379 [tdict setObject: [NSNumber numberWithFloat: 0.0]
380 forKey: NSFontWeightTrait]; 380 forKey: NSFontWeightTrait];
381 } 381 }
382 } 382 }
383 383
384 tem = AREF (font_spec, FONT_SPACING_INDEX); 384 tem = AREF (font_spec, FONT_SPACING_INDEX);
385 385
386 if (family != nil) 386 if (family != nil)
387 { 387 [fdAttrs setObject: family
388 [fdAttrs setObject: family 388 forKey: NSFontFamilyAttribute];
389 forKey: NSFontFamilyAttribute];
390 }
391 389
392 if (FIXNUMP (tem)) 390 if (FIXNUMP (tem))
393 { 391 {
394 if (XFIXNUM (tem) != FONT_SPACING_PROPORTIONAL) 392 if (XFIXNUM (tem) != FONT_SPACING_PROPORTIONAL)
395 { 393 [fdAttrs setObject: [NSNumber numberWithBool: YES]
396 [fdAttrs setObject: [NSNumber numberWithBool:YES] 394 forKey: NSFontFixedAdvanceAttribute];
397 forKey: NSFontFixedAdvanceAttribute]; 395 else
398 } 396 [fdAttrs setObject: [NSNumber numberWithBool: NO]
399 else 397 forKey: NSFontFixedAdvanceAttribute];
400 { 398 }
401 [fdAttrs setObject: [NSNumber numberWithBool:NO]
402 forKey: NSFontFixedAdvanceAttribute];
403 }
404 }
405 399
406 /* Handle special families such as ``fixed'' or ``Sans Serif''. */ 400 /* Handle special families such as ``fixed'', ``monospace'' or
401 ``Sans Serif''. */
407 402
408 if ([family isEqualToString: @"fixed"]) 403 if ([family isEqualToString: @"fixed"]
409 { 404 || [family isEqualToString: @"monospace"])
410 [fdAttrs setObject: [[NSFont userFixedPitchFontOfSize: 0] familyName] 405 [fdAttrs setObject: [[NSFont userFixedPitchFontOfSize: 0] familyName]
411 forKey: NSFontFamilyAttribute]; 406 forKey: NSFontFamilyAttribute];
412 } 407 else if ([family isEqualToString: @"Sans Serif"])
413 else if ([family isEqualToString: @"Sans Serif"]) 408 [fdAttrs setObject: [[NSFont userFontOfSize: 0] familyName]
414 { 409 forKey: NSFontFamilyAttribute];
415 [fdAttrs setObject: [[NSFont userFontOfSize: 0] familyName]
416 forKey: NSFontFamilyAttribute];
417 }
418 410
419 [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute]; 411 [fdAttrs setObject: tdict forKey: NSFontTraitsAttribute];
420 412
421 fdesc = [[[NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs] 413 fdesc = [[[NSFontDescriptor fontDescriptorWithFontAttributes: fdAttrs]
422 retain] autorelease]; 414 retain] autorelease];
423 415
424 [tdict release]; 416 [tdict release];
425 [fdAttrs release]; 417 [fdAttrs release];
426 return fdesc; 418 return fdesc;
427} 419}
428 420
429 421
@@ -477,7 +469,7 @@ ns_descriptor_to_entity (NSFontDescriptor *desc,
477 ASET (font_entity, FONT_SIZE_INDEX, make_fixnum (0)); 469 ASET (font_entity, FONT_SIZE_INDEX, make_fixnum (0));
478 ASET (font_entity, FONT_AVGWIDTH_INDEX, make_fixnum (0)); 470 ASET (font_entity, FONT_AVGWIDTH_INDEX, make_fixnum (0));
479 ASET (font_entity, FONT_SPACING_INDEX, 471 ASET (font_entity, FONT_SPACING_INDEX,
480 make_fixnum ((data.specified & GS_SPECIFIED_WIDTH && data.monospace_p) 472 make_fixnum ((data.specified & GS_SPECIFIED_SPACING && data.monospace_p)
481 ? FONT_SPACING_MONO : FONT_SPACING_PROPORTIONAL)); 473 ? FONT_SPACING_MONO : FONT_SPACING_PROPORTIONAL));
482 474
483 ASET (font_entity, FONT_EXTRA_INDEX, extra); 475 ASET (font_entity, FONT_EXTRA_INDEX, extra);
@@ -792,53 +784,53 @@ static NSSet
792static Lisp_Object 784static Lisp_Object
793ns_findfonts (Lisp_Object font_spec, BOOL isMatch) 785ns_findfonts (Lisp_Object font_spec, BOOL isMatch)
794{ 786{
795 Lisp_Object tem, list = Qnil; 787 Lisp_Object tem, list = Qnil;
796 NSFontDescriptor *fdesc; 788 NSFontDescriptor *fdesc;
797 NSArray *all_descs; 789 NSArray *all_descs;
798 GSFontEnumerator *enumerator = [GSFontEnumerator sharedEnumerator]; 790 GSFontEnumerator *enumerator = [GSFontEnumerator sharedEnumerator];
799 791
800 NSSet *cFamilies; 792 NSSet *cFamilies;
801 793
802 block_input (); 794 block_input ();
803 if (NSFONT_TRACE) 795 if (NSFONT_TRACE)
804 { 796 {
805 fprintf (stderr, "nsfont: %s for fontspec:\n ", 797 fprintf (stderr, "nsfont: %s for fontspec:\n ",
806 (isMatch ? "match" : "list")); 798 (isMatch ? "match" : "list"));
807 debug_print (font_spec); 799 debug_print (font_spec);
808 } 800 }
809 801
810 cFamilies = ns_get_covering_families (ns_get_req_script (font_spec), 0.90); 802 cFamilies = ns_get_covering_families (ns_get_req_script (font_spec), 0.90);
811 803
812 fdesc = ns_spec_to_descriptor (font_spec); 804 fdesc = ns_spec_to_descriptor (font_spec);
813 all_descs = [enumerator availableFontDescriptors]; 805 all_descs = [enumerator availableFontDescriptors];
814 806
815 for (NSFontDescriptor *desc in all_descs) 807 for (NSFontDescriptor *desc in all_descs)
816 { 808 {
817 if (![cFamilies containsObject: 809 if (![cFamilies containsObject:
818 [desc objectForKey: NSFontFamilyAttribute]]) 810 [desc objectForKey: NSFontFamilyAttribute]])
819 continue; 811 continue;
820 if (!ns_font_descs_match_p (fdesc, desc)) 812 if (!ns_font_descs_match_p (fdesc, desc))
821 continue; 813 continue;
822 814
823 tem = ns_descriptor_to_entity (desc, 815 tem = ns_descriptor_to_entity (desc,
824 AREF (font_spec, FONT_EXTRA_INDEX), 816 AREF (font_spec, FONT_EXTRA_INDEX),
825 NULL); 817 NULL);
826 if (isMatch) 818 if (isMatch)
827 return tem; 819 return tem;
828 list = Fcons (tem, list); 820 list = Fcons (tem, list);
829 } 821 }
830 822
831 unblock_input (); 823 unblock_input ();
832 824
833 /* Return something if was a match and nothing found. */ 825 /* Return something if was a match and nothing found. */
834 if (isMatch) 826 if (isMatch)
835 return ns_fallback_entity (); 827 return ns_fallback_entity ();
836 828
837 if (NSFONT_TRACE) 829 if (NSFONT_TRACE)
838 fprintf (stderr, " Returning %"pD"d entities.\n", 830 fprintf (stderr, " Returning %"pD"d entities.\n",
839 list_length (list)); 831 list_length (list));
840 832
841 return list; 833 return list;
842} 834}
843 835
844 836