comparison src/nsterm.m @ 104373:76f05970298e

(ns_get_color): Remove incompatible color formats again.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Thu, 20 Aug 2009 09:44:15 +0000
parents 13c45bf5b233
children 73dca9808fbe
comparison
equal deleted inserted replaced
104372:c1f72ea59c48 104373:76f05970298e
1346 /* -------------------------------------------------------------------------- 1346 /* --------------------------------------------------------------------------
1347 Parse a color name 1347 Parse a color name
1348 /* -------------------------------------------------------------------------- 1348 /* --------------------------------------------------------------------------
1349 /* On *Step, we recognize several color formats, in addition to a catalog 1349 /* On *Step, we recognize several color formats, in addition to a catalog
1350 of colors found in the file Emacs.clr. Color formats include: 1350 of colors found in the file Emacs.clr. Color formats include:
1351 - #rrggbb or RGBrrggbb where rr, gg, bb specify red, green and blue in hex 1351 - #rrggbb where rr, gg, bb specify red, green and blue in hex. */
1352 - ARGBaarrggbb is similar, with aa being the alpha channel (FF = opaque)
1353 - HSVhhssvv and AHSVaahhssvv (or HSB/AHSB) are similar for hue, saturation,
1354 value;
1355 - CMYKccmmyykk is similar for cyan, magenta, yellow, black. */
1356 { 1352 {
1357 NSColor * new = nil; 1353 NSColor * new = nil;
1358 const char *hex = NULL; 1354 const char *hex = NULL;
1359 enum { rgb, argb, hsv, ahsv, cmyk, gray } color_space; 1355 enum { rgb } color_space;
1360 NSString *nsname = [NSString stringWithUTF8String: name]; 1356 NSString *nsname = [NSString stringWithUTF8String: name];
1361 1357
1362 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */ 1358 /*fprintf (stderr, "ns_get_color: '%s'\n", name); */
1363 BLOCK_INPUT; 1359 BLOCK_INPUT;
1364 1360
1379 *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0]; 1375 *col = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: 1.0];
1380 UNBLOCK_INPUT; 1376 UNBLOCK_INPUT;
1381 return 0; 1377 return 0;
1382 } 1378 }
1383 1379
1384 /* FIXME: emacs seems to downcase everything before passing it here,
1385 which we can work around, except for GRAY, since gray##, where ## is
1386 decimal between 0 and 99, is also an X11 colorname. */
1387 if (name[0] == '#') /* X11 format */ 1380 if (name[0] == '#') /* X11 format */
1388 { 1381 {
1389 hex = name + 1; 1382 hex = name + 1;
1390 color_space = rgb; 1383 color_space = rgb;
1391 }
1392 else if (!memcmp (name, "RGB", 3) || !memcmp (name, "rgb", 3))
1393 {
1394 hex = name + 3;
1395 color_space = rgb;
1396 }
1397 else if (!memcmp (name, "ARGB", 4) || !memcmp (name, "argb", 4))
1398 {
1399 hex = name + 4;
1400 color_space = argb;
1401 }
1402 else if (!memcmp (name, "HSV", 3) || !memcmp (name, "hsv", 3) ||
1403 !memcmp (name, "HSB", 3) || !memcmp (name, "hsb", 3))
1404 {
1405 hex = name + 3;
1406 color_space = hsv;
1407 }
1408 else if (!memcmp (name, "AHSV", 4) || !memcmp (name, "ahsv", 4) ||
1409 !memcmp (name, "AHSB", 4) || !memcmp (name, "ahsb", 4))
1410 {
1411 hex = name + 4;
1412 color_space = ahsv;
1413 }
1414 else if (!memcmp (name, "CMYK", 4) || !memcmp (name, "cmyk", 4))
1415 {
1416 hex = name + 4;
1417 color_space = cmyk;
1418 }
1419 else if (!memcmp (name, "GRAY", 4) /*|| !memcmp (name, "gray", 4)*/)
1420 {
1421 hex = name + 4;
1422 color_space = gray;
1423 } 1384 }
1424 1385
1425 /* Direct colors (hex values) */ 1386 /* Direct colors (hex values) */
1426 if (hex) 1387 if (hex)
1427 { 1388 {
1447 case rgb: 1408 case rgb:
1448 *col = [NSColor colorWithCalibratedRed: f2 1409 *col = [NSColor colorWithCalibratedRed: f2
1449 green: f3 1410 green: f3
1450 blue: f4 1411 blue: f4
1451 alpha: 1.0]; 1412 alpha: 1.0];
1452 break;
1453 case argb:
1454 *col = [NSColor colorWithCalibratedRed: f2
1455 green: f3
1456 blue: f4
1457 alpha: f1];
1458 break;
1459 case hsv:
1460 *col = [NSColor colorWithCalibratedHue: f2
1461 saturation: f3
1462 brightness: f4
1463 alpha: 1.0];
1464 break;
1465 case ahsv:
1466 *col = [NSColor colorWithCalibratedHue: f2
1467 saturation: f3
1468 brightness: f4
1469 alpha: f1];
1470 break;
1471 case gray:
1472 *col = [NSColor colorWithCalibratedWhite: f3 alpha: f4];
1473 break;
1474 case cmyk:
1475 *col = [NSColor colorWithDeviceCyan: f1
1476 magenta: f2
1477 yellow: f3
1478 black: f4
1479 alpha: 1.0];
1480 break; 1413 break;
1481 } 1414 }
1482 *col = [*col colorUsingColorSpaceName: NSCalibratedRGBColorSpace]; 1415 *col = [*col colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
1483 UNBLOCK_INPUT; 1416 UNBLOCK_INPUT;
1484 return 0; 1417 return 0;