Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: third_party/WebKit/Source/platform/fonts/shaping/HarfBuzzShaper.cpp

Issue 2517023002: Revert of Minor style changes to HarfBuzzShaper to improve readability (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved. 3 * Copyright (C) 2013 BlackBerry Limited. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 Deque<HolesQueueItem>* queue, 372 Deque<HolesQueueItem>* queue,
373 HolesQueueItem& currentQueueItem, 373 HolesQueueItem& currentQueueItem,
374 SmallCapsIterator::SmallCapsBehavior& smallCapsBehavior) { 374 SmallCapsIterator::SmallCapsBehavior& smallCapsBehavior) {
375 unsigned numCharactersUntilCaseChange = 0; 375 unsigned numCharactersUntilCaseChange = 0;
376 SmallCapsIterator smallCapsIterator( 376 SmallCapsIterator smallCapsIterator(
377 normalizedBuffer + currentQueueItem.m_startIndex, 377 normalizedBuffer + currentQueueItem.m_startIndex,
378 currentQueueItem.m_numCharacters); 378 currentQueueItem.m_numCharacters);
379 smallCapsIterator.consume(&numCharactersUntilCaseChange, &smallCapsBehavior); 379 smallCapsIterator.consume(&numCharactersUntilCaseChange, &smallCapsBehavior);
380 if (numCharactersUntilCaseChange > 0 && 380 if (numCharactersUntilCaseChange > 0 &&
381 numCharactersUntilCaseChange < currentQueueItem.m_numCharacters) { 381 numCharactersUntilCaseChange < currentQueueItem.m_numCharacters) {
382 queue->prepend(HolesQueueItem( 382 unsigned startIndex =
383 HolesQueueItemAction::HolesQueueRange, 383 currentQueueItem.m_startIndex + numCharactersUntilCaseChange;
384 currentQueueItem.m_startIndex + numCharactersUntilCaseChange, 384 unsigned numCharacters =
385 currentQueueItem.m_numCharacters - numCharactersUntilCaseChange)); 385 currentQueueItem.m_numCharacters - numCharactersUntilCaseChange;
386 queue->prepend(HolesQueueItem(HolesQueueItemAction::HolesQueueRange,
387 startIndex, numCharacters));
386 currentQueueItem.m_numCharacters = numCharactersUntilCaseChange; 388 currentQueueItem.m_numCharacters = numCharactersUntilCaseChange;
387 } 389 }
388 } 390 }
389 391
390 hb_feature_t createFeature(hb_tag_t tag, uint32_t value = 0) { 392 hb_feature_t createFeature(uint8_t c1,
391 return {tag, value, 0 /* start */, static_cast<unsigned>(-1) /* end */}; 393 uint8_t c2,
394 uint8_t c3,
395 uint8_t c4,
396 uint32_t value = 0) {
397 return {HB_TAG(c1, c2, c3, c4), value, 0 /* start */,
398 static_cast<unsigned>(-1) /* end */};
392 } 399 }
393 400
394 void setFontFeatures(const Font* font, 401 void setFontFeatures(const Font* font,
395 HarfBuzzShaper::FeaturesVector* features) { 402 HarfBuzzShaper::FeaturesVector* features) {
396 const FontDescription& description = font->getFontDescription(); 403 const FontDescription& description = font->getFontDescription();
397 404
398 static hb_feature_t noKern = createFeature(HB_TAG('k', 'e', 'r', 'n')); 405 static hb_feature_t noKern = createFeature('k', 'e', 'r', 'n');
399 static hb_feature_t noVkrn = createFeature(HB_TAG('v', 'k', 'r', 'n')); 406 static hb_feature_t noVkrn = createFeature('v', 'k', 'r', 'n');
400 switch (description.getKerning()) { 407 switch (description.getKerning()) {
401 case FontDescription::NormalKerning: 408 case FontDescription::NormalKerning:
402 // kern/vkrn are enabled by default 409 // kern/vkrn are enabled by default
403 break; 410 break;
404 case FontDescription::NoneKerning: 411 case FontDescription::NoneKerning:
405 features->append(description.isVerticalAnyUpright() ? noVkrn : noKern); 412 features->append(description.isVerticalAnyUpright() ? noVkrn : noKern);
406 break; 413 break;
407 case FontDescription::AutoKerning: 414 case FontDescription::AutoKerning:
408 break; 415 break;
409 } 416 }
410 417
411 static hb_feature_t noClig = createFeature(HB_TAG('c', 'l', 'i', 'g')); 418 static hb_feature_t noClig = createFeature('c', 'l', 'i', 'g');
412 static hb_feature_t noLiga = createFeature(HB_TAG('l', 'i', 'g', 'a')); 419 static hb_feature_t noLiga = createFeature('l', 'i', 'g', 'a');
413 switch (description.commonLigaturesState()) { 420 switch (description.commonLigaturesState()) {
414 case FontDescription::DisabledLigaturesState: 421 case FontDescription::DisabledLigaturesState:
415 features->append(noLiga); 422 features->append(noLiga);
416 features->append(noClig); 423 features->append(noClig);
417 break; 424 break;
418 case FontDescription::EnabledLigaturesState: 425 case FontDescription::EnabledLigaturesState:
419 // liga and clig are on by default 426 // liga and clig are on by default
420 break; 427 break;
421 case FontDescription::NormalLigaturesState: 428 case FontDescription::NormalLigaturesState:
422 break; 429 break;
423 } 430 }
424 static hb_feature_t dlig = createFeature(HB_TAG('d', 'l', 'i', 'g'), 1); 431 static hb_feature_t dlig = createFeature('d', 'l', 'i', 'g', 1);
425 switch (description.discretionaryLigaturesState()) { 432 switch (description.discretionaryLigaturesState()) {
426 case FontDescription::DisabledLigaturesState: 433 case FontDescription::DisabledLigaturesState:
427 // dlig is off by default 434 // dlig is off by default
428 break; 435 break;
429 case FontDescription::EnabledLigaturesState: 436 case FontDescription::EnabledLigaturesState:
430 features->append(dlig); 437 features->append(dlig);
431 break; 438 break;
432 case FontDescription::NormalLigaturesState: 439 case FontDescription::NormalLigaturesState:
433 break; 440 break;
434 } 441 }
435 static hb_feature_t hlig = createFeature(HB_TAG('h', 'l', 'i', 'g'), 1); 442 static hb_feature_t hlig = createFeature('h', 'l', 'i', 'g', 1);
436 switch (description.historicalLigaturesState()) { 443 switch (description.historicalLigaturesState()) {
437 case FontDescription::DisabledLigaturesState: 444 case FontDescription::DisabledLigaturesState:
438 // hlig is off by default 445 // hlig is off by default
439 break; 446 break;
440 case FontDescription::EnabledLigaturesState: 447 case FontDescription::EnabledLigaturesState:
441 features->append(hlig); 448 features->append(hlig);
442 break; 449 break;
443 case FontDescription::NormalLigaturesState: 450 case FontDescription::NormalLigaturesState:
444 break; 451 break;
445 } 452 }
446 static hb_feature_t noCalt = createFeature(HB_TAG('c', 'a', 'l', 't')); 453 static hb_feature_t noCalt = createFeature('c', 'a', 'l', 't');
447 switch (description.contextualLigaturesState()) { 454 switch (description.contextualLigaturesState()) {
448 case FontDescription::DisabledLigaturesState: 455 case FontDescription::DisabledLigaturesState:
449 features->append(noCalt); 456 features->append(noCalt);
450 break; 457 break;
451 case FontDescription::EnabledLigaturesState: 458 case FontDescription::EnabledLigaturesState:
452 // calt is on by default 459 // calt is on by default
453 break; 460 break;
454 case FontDescription::NormalLigaturesState: 461 case FontDescription::NormalLigaturesState:
455 break; 462 break;
456 } 463 }
457 464
458 static hb_feature_t hwid = createFeature(HB_TAG('h', 'w', 'i', 'd'), 1); 465 static hb_feature_t hwid = createFeature('h', 'w', 'i', 'd', 1);
459 static hb_feature_t twid = createFeature(HB_TAG('t', 'w', 'i', 'd'), 1); 466 static hb_feature_t twid = createFeature('t', 'w', 'i', 'd', 1);
460 static hb_feature_t qwid = createFeature(HB_TAG('q', 'w', 'i', 'd'), 1); 467 static hb_feature_t qwid = createFeature('q', 'w', 'i', 'd', 1);
461 switch (description.widthVariant()) { 468 switch (description.widthVariant()) {
462 case HalfWidth: 469 case HalfWidth:
463 features->append(hwid); 470 features->append(hwid);
464 break; 471 break;
465 case ThirdWidth: 472 case ThirdWidth:
466 features->append(twid); 473 features->append(twid);
467 break; 474 break;
468 case QuarterWidth: 475 case QuarterWidth:
469 features->append(qwid); 476 features->append(qwid);
470 break; 477 break;
471 case RegularWidth: 478 case RegularWidth:
472 break; 479 break;
473 } 480 }
474 481
475 // font-variant-numeric: 482 // font-variant-numeric:
476 static hb_feature_t lnum = createFeature(HB_TAG('l', 'n', 'u', 'm'), 1); 483 static hb_feature_t lnum = createFeature('l', 'n', 'u', 'm', 1);
477 if (description.variantNumeric().numericFigureValue() == 484 if (description.variantNumeric().numericFigureValue() ==
478 FontVariantNumeric::LiningNums) 485 FontVariantNumeric::LiningNums)
479 features->append(lnum); 486 features->append(lnum);
480 487
481 static hb_feature_t onum = createFeature(HB_TAG('o', 'n', 'u', 'm'), 1); 488 static hb_feature_t onum = createFeature('o', 'n', 'u', 'm', 1);
482 if (description.variantNumeric().numericFigureValue() == 489 if (description.variantNumeric().numericFigureValue() ==
483 FontVariantNumeric::OldstyleNums) 490 FontVariantNumeric::OldstyleNums)
484 features->append(onum); 491 features->append(onum);
485 492
486 static hb_feature_t pnum = createFeature(HB_TAG('p', 'n', 'u', 'm'), 1); 493 static hb_feature_t pnum = createFeature('p', 'n', 'u', 'm', 1);
487 if (description.variantNumeric().numericSpacingValue() == 494 if (description.variantNumeric().numericSpacingValue() ==
488 FontVariantNumeric::ProportionalNums) 495 FontVariantNumeric::ProportionalNums)
489 features->append(pnum); 496 features->append(pnum);
490 static hb_feature_t tnum = createFeature(HB_TAG('t', 'n', 'u', 'm'), 1); 497 static hb_feature_t tnum = createFeature('t', 'n', 'u', 'm', 1);
491 if (description.variantNumeric().numericSpacingValue() == 498 if (description.variantNumeric().numericSpacingValue() ==
492 FontVariantNumeric::TabularNums) 499 FontVariantNumeric::TabularNums)
493 features->append(tnum); 500 features->append(tnum);
494 501
495 static hb_feature_t afrc = createFeature(HB_TAG('a', 'f', 'r', 'c'), 1); 502 static hb_feature_t afrc = createFeature('a', 'f', 'r', 'c', 1);
496 if (description.variantNumeric().numericFractionValue() == 503 if (description.variantNumeric().numericFractionValue() ==
497 FontVariantNumeric::StackedFractions) 504 FontVariantNumeric::StackedFractions)
498 features->append(afrc); 505 features->append(afrc);
499 static hb_feature_t frac = createFeature(HB_TAG('f', 'r', 'a', 'c'), 1); 506 static hb_feature_t frac = createFeature('f', 'r', 'a', 'c', 1);
500 if (description.variantNumeric().numericFractionValue() == 507 if (description.variantNumeric().numericFractionValue() ==
501 FontVariantNumeric::DiagonalFractions) 508 FontVariantNumeric::DiagonalFractions)
502 features->append(frac); 509 features->append(frac);
503 510
504 static hb_feature_t ordn = createFeature(HB_TAG('o', 'r', 'd', 'n'), 1); 511 static hb_feature_t ordn = createFeature('o', 'r', 'd', 'n', 1);
505 if (description.variantNumeric().ordinalValue() == 512 if (description.variantNumeric().ordinalValue() ==
506 FontVariantNumeric::OrdinalOn) 513 FontVariantNumeric::OrdinalOn)
507 features->append(ordn); 514 features->append(ordn);
508 515
509 static hb_feature_t zero = createFeature(HB_TAG('z', 'e', 'r', 'o'), 1); 516 static hb_feature_t zero = createFeature('z', 'e', 'r', 'o', 1);
510 if (description.variantNumeric().slashedZeroValue() == 517 if (description.variantNumeric().slashedZeroValue() ==
511 FontVariantNumeric::SlashedZeroOn) 518 FontVariantNumeric::SlashedZeroOn)
512 features->append(zero); 519 features->append(zero);
513 520
514 FontFeatureSettings* settings = description.featureSettings(); 521 FontFeatureSettings* settings = description.featureSettings();
515 if (!settings) 522 if (!settings)
516 return; 523 return;
517 524
518 // TODO(drott): crbug.com/450619 Implement feature resolution instead of 525 // TODO(drott): crbug.com/450619 Implement feature resolution instead of
519 // just appending the font-feature-settings. 526 // just appending the font-feature-settings.
(...skipping 27 matching lines...) Expand all
547 554
548 CapsFeatureSettingsScopedOverlay::CapsFeatureSettingsScopedOverlay( 555 CapsFeatureSettingsScopedOverlay::CapsFeatureSettingsScopedOverlay(
549 HarfBuzzShaper::FeaturesVector* features, 556 HarfBuzzShaper::FeaturesVector* features,
550 FontDescription::FontVariantCaps variantCaps) 557 FontDescription::FontVariantCaps variantCaps)
551 : m_features(features), m_countFeatures(0) { 558 : m_features(features), m_countFeatures(0) {
552 overlayCapsFeatures(variantCaps); 559 overlayCapsFeatures(variantCaps);
553 } 560 }
554 561
555 void CapsFeatureSettingsScopedOverlay::overlayCapsFeatures( 562 void CapsFeatureSettingsScopedOverlay::overlayCapsFeatures(
556 FontDescription::FontVariantCaps variantCaps) { 563 FontDescription::FontVariantCaps variantCaps) {
557 static hb_feature_t smcp = createFeature(HB_TAG('s', 'm', 'c', 'p'), 1); 564 static hb_feature_t smcp = createFeature('s', 'm', 'c', 'p', 1);
558 static hb_feature_t pcap = createFeature(HB_TAG('p', 'c', 'a', 'p'), 1); 565 static hb_feature_t pcap = createFeature('p', 'c', 'a', 'p', 1);
559 static hb_feature_t c2sc = createFeature(HB_TAG('c', '2', 's', 'c'), 1); 566 static hb_feature_t c2sc = createFeature('c', '2', 's', 'c', 1);
560 static hb_feature_t c2pc = createFeature(HB_TAG('c', '2', 'p', 'c'), 1); 567 static hb_feature_t c2pc = createFeature('c', '2', 'p', 'c', 1);
561 static hb_feature_t unic = createFeature(HB_TAG('u', 'n', 'i', 'c'), 1); 568 static hb_feature_t unic = createFeature('u', 'n', 'i', 'c', 1);
562 static hb_feature_t titl = createFeature(HB_TAG('t', 'i', 't', 'l'), 1); 569 static hb_feature_t titl = createFeature('t', 'i', 't', 'l', 1);
563 if (variantCaps == FontDescription::SmallCaps || 570 if (variantCaps == FontDescription::SmallCaps ||
564 variantCaps == FontDescription::AllSmallCaps) { 571 variantCaps == FontDescription::AllSmallCaps) {
565 prependCounting(smcp); 572 prependCounting(smcp);
566 if (variantCaps == FontDescription::AllSmallCaps) { 573 if (variantCaps == FontDescription::AllSmallCaps) {
567 prependCounting(c2sc); 574 prependCounting(c2sc);
568 } 575 }
569 } 576 }
570 if (variantCaps == FontDescription::PetiteCaps || 577 if (variantCaps == FontDescription::PetiteCaps ||
571 variantCaps == FontDescription::AllPetiteCaps) { 578 variantCaps == FontDescription::AllPetiteCaps) {
572 prependCounting(pcap); 579 prependCounting(pcap);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 segmentRange.script, !fallbackIterator->hasNext())) 725 segmentRange.script, !fallbackIterator->hasNext()))
719 DLOG(ERROR) << "Shape result extraction failed."; 726 DLOG(ERROR) << "Shape result extraction failed.";
720 727
721 hb_buffer_reset(harfBuzzBuffer.get()); 728 hb_buffer_reset(harfBuzzBuffer.get());
722 } 729 }
723 } 730 }
724 return result.release(); 731 return result.release();
725 } 732 }
726 733
727 } // namespace blink 734 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698