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

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

Issue 2517193002: Reland of Minor style changes to HarfBuzzShaper to improve readability (Closed)
Patch Set: Rebase again Created 4 years 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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 Deque<HolesQueueItem>* queue, 325 Deque<HolesQueueItem>* queue,
326 HolesQueueItem& currentQueueItem, 326 HolesQueueItem& currentQueueItem,
327 SmallCapsIterator::SmallCapsBehavior& smallCapsBehavior) { 327 SmallCapsIterator::SmallCapsBehavior& smallCapsBehavior) {
328 unsigned numCharactersUntilCaseChange = 0; 328 unsigned numCharactersUntilCaseChange = 0;
329 SmallCapsIterator smallCapsIterator( 329 SmallCapsIterator smallCapsIterator(
330 normalizedBuffer + currentQueueItem.m_startIndex, 330 normalizedBuffer + currentQueueItem.m_startIndex,
331 currentQueueItem.m_numCharacters); 331 currentQueueItem.m_numCharacters);
332 smallCapsIterator.consume(&numCharactersUntilCaseChange, &smallCapsBehavior); 332 smallCapsIterator.consume(&numCharactersUntilCaseChange, &smallCapsBehavior);
333 if (numCharactersUntilCaseChange > 0 && 333 if (numCharactersUntilCaseChange > 0 &&
334 numCharactersUntilCaseChange < currentQueueItem.m_numCharacters) { 334 numCharactersUntilCaseChange < currentQueueItem.m_numCharacters) {
335 unsigned startIndex = 335 queue->prepend(HolesQueueItem(
336 currentQueueItem.m_startIndex + numCharactersUntilCaseChange; 336 HolesQueueItemAction::HolesQueueRange,
337 unsigned numCharacters = 337 currentQueueItem.m_startIndex + numCharactersUntilCaseChange,
338 currentQueueItem.m_numCharacters - numCharactersUntilCaseChange; 338 currentQueueItem.m_numCharacters - numCharactersUntilCaseChange));
339 queue->prepend(HolesQueueItem(HolesQueueItemAction::HolesQueueRange,
340 startIndex, numCharacters));
341 currentQueueItem.m_numCharacters = numCharactersUntilCaseChange; 339 currentQueueItem.m_numCharacters = numCharactersUntilCaseChange;
342 } 340 }
343 } 341 }
344 342
345 hb_feature_t createFeature(uint8_t c1, 343 hb_feature_t createFeature(hb_tag_t tag, uint32_t value = 0) {
346 uint8_t c2, 344 return {tag, value, 0 /* start */, static_cast<unsigned>(-1) /* end */};
347 uint8_t c3,
348 uint8_t c4,
349 uint32_t value = 0) {
350 return {HB_TAG(c1, c2, c3, c4), value, 0 /* start */,
351 static_cast<unsigned>(-1) /* end */};
352 } 345 }
353 346
354 void setFontFeatures(const Font* font, FeaturesVector* features) { 347 void setFontFeatures(const Font* font, FeaturesVector* features) {
355 const FontDescription& description = font->getFontDescription(); 348 const FontDescription& description = font->getFontDescription();
356 349
357 static hb_feature_t noKern = createFeature('k', 'e', 'r', 'n'); 350 static hb_feature_t noKern = createFeature(HB_TAG('k', 'e', 'r', 'n'));
358 static hb_feature_t noVkrn = createFeature('v', 'k', 'r', 'n'); 351 static hb_feature_t noVkrn = createFeature(HB_TAG('v', 'k', 'r', 'n'));
359 switch (description.getKerning()) { 352 switch (description.getKerning()) {
360 case FontDescription::NormalKerning: 353 case FontDescription::NormalKerning:
361 // kern/vkrn are enabled by default 354 // kern/vkrn are enabled by default
362 break; 355 break;
363 case FontDescription::NoneKerning: 356 case FontDescription::NoneKerning:
364 features->append(description.isVerticalAnyUpright() ? noVkrn : noKern); 357 features->append(description.isVerticalAnyUpright() ? noVkrn : noKern);
365 break; 358 break;
366 case FontDescription::AutoKerning: 359 case FontDescription::AutoKerning:
367 break; 360 break;
368 } 361 }
369 362
370 static hb_feature_t noClig = createFeature('c', 'l', 'i', 'g'); 363 static hb_feature_t noClig = createFeature(HB_TAG('c', 'l', 'i', 'g'));
371 static hb_feature_t noLiga = createFeature('l', 'i', 'g', 'a'); 364 static hb_feature_t noLiga = createFeature(HB_TAG('l', 'i', 'g', 'a'));
372 switch (description.commonLigaturesState()) { 365 switch (description.commonLigaturesState()) {
373 case FontDescription::DisabledLigaturesState: 366 case FontDescription::DisabledLigaturesState:
374 features->append(noLiga); 367 features->append(noLiga);
375 features->append(noClig); 368 features->append(noClig);
376 break; 369 break;
377 case FontDescription::EnabledLigaturesState: 370 case FontDescription::EnabledLigaturesState:
378 // liga and clig are on by default 371 // liga and clig are on by default
379 break; 372 break;
380 case FontDescription::NormalLigaturesState: 373 case FontDescription::NormalLigaturesState:
381 break; 374 break;
382 } 375 }
383 static hb_feature_t dlig = createFeature('d', 'l', 'i', 'g', 1); 376 static hb_feature_t dlig = createFeature(HB_TAG('d', 'l', 'i', 'g'), 1);
384 switch (description.discretionaryLigaturesState()) { 377 switch (description.discretionaryLigaturesState()) {
385 case FontDescription::DisabledLigaturesState: 378 case FontDescription::DisabledLigaturesState:
386 // dlig is off by default 379 // dlig is off by default
387 break; 380 break;
388 case FontDescription::EnabledLigaturesState: 381 case FontDescription::EnabledLigaturesState:
389 features->append(dlig); 382 features->append(dlig);
390 break; 383 break;
391 case FontDescription::NormalLigaturesState: 384 case FontDescription::NormalLigaturesState:
392 break; 385 break;
393 } 386 }
394 static hb_feature_t hlig = createFeature('h', 'l', 'i', 'g', 1); 387 static hb_feature_t hlig = createFeature(HB_TAG('h', 'l', 'i', 'g'), 1);
395 switch (description.historicalLigaturesState()) { 388 switch (description.historicalLigaturesState()) {
396 case FontDescription::DisabledLigaturesState: 389 case FontDescription::DisabledLigaturesState:
397 // hlig is off by default 390 // hlig is off by default
398 break; 391 break;
399 case FontDescription::EnabledLigaturesState: 392 case FontDescription::EnabledLigaturesState:
400 features->append(hlig); 393 features->append(hlig);
401 break; 394 break;
402 case FontDescription::NormalLigaturesState: 395 case FontDescription::NormalLigaturesState:
403 break; 396 break;
404 } 397 }
405 static hb_feature_t noCalt = createFeature('c', 'a', 'l', 't'); 398 static hb_feature_t noCalt = createFeature(HB_TAG('c', 'a', 'l', 't'));
406 switch (description.contextualLigaturesState()) { 399 switch (description.contextualLigaturesState()) {
407 case FontDescription::DisabledLigaturesState: 400 case FontDescription::DisabledLigaturesState:
408 features->append(noCalt); 401 features->append(noCalt);
409 break; 402 break;
410 case FontDescription::EnabledLigaturesState: 403 case FontDescription::EnabledLigaturesState:
411 // calt is on by default 404 // calt is on by default
412 break; 405 break;
413 case FontDescription::NormalLigaturesState: 406 case FontDescription::NormalLigaturesState:
414 break; 407 break;
415 } 408 }
416 409
417 static hb_feature_t hwid = createFeature('h', 'w', 'i', 'd', 1); 410 static hb_feature_t hwid = createFeature(HB_TAG('h', 'w', 'i', 'd'), 1);
418 static hb_feature_t twid = createFeature('t', 'w', 'i', 'd', 1); 411 static hb_feature_t twid = createFeature(HB_TAG('t', 'w', 'i', 'd'), 1);
419 static hb_feature_t qwid = createFeature('q', 'w', 'i', 'd', 1); 412 static hb_feature_t qwid = createFeature(HB_TAG('q', 'w', 'i', 'd'), 1);
420 switch (description.widthVariant()) { 413 switch (description.widthVariant()) {
421 case HalfWidth: 414 case HalfWidth:
422 features->append(hwid); 415 features->append(hwid);
423 break; 416 break;
424 case ThirdWidth: 417 case ThirdWidth:
425 features->append(twid); 418 features->append(twid);
426 break; 419 break;
427 case QuarterWidth: 420 case QuarterWidth:
428 features->append(qwid); 421 features->append(qwid);
429 break; 422 break;
430 case RegularWidth: 423 case RegularWidth:
431 break; 424 break;
432 } 425 }
433 426
434 // font-variant-numeric: 427 // font-variant-numeric:
435 static hb_feature_t lnum = createFeature('l', 'n', 'u', 'm', 1); 428 static hb_feature_t lnum = createFeature(HB_TAG('l', 'n', 'u', 'm'), 1);
436 if (description.variantNumeric().numericFigureValue() == 429 if (description.variantNumeric().numericFigureValue() ==
437 FontVariantNumeric::LiningNums) 430 FontVariantNumeric::LiningNums)
438 features->append(lnum); 431 features->append(lnum);
439 432
440 static hb_feature_t onum = createFeature('o', 'n', 'u', 'm', 1); 433 static hb_feature_t onum = createFeature(HB_TAG('o', 'n', 'u', 'm'), 1);
441 if (description.variantNumeric().numericFigureValue() == 434 if (description.variantNumeric().numericFigureValue() ==
442 FontVariantNumeric::OldstyleNums) 435 FontVariantNumeric::OldstyleNums)
443 features->append(onum); 436 features->append(onum);
444 437
445 static hb_feature_t pnum = createFeature('p', 'n', 'u', 'm', 1); 438 static hb_feature_t pnum = createFeature(HB_TAG('p', 'n', 'u', 'm'), 1);
446 if (description.variantNumeric().numericSpacingValue() == 439 if (description.variantNumeric().numericSpacingValue() ==
447 FontVariantNumeric::ProportionalNums) 440 FontVariantNumeric::ProportionalNums)
448 features->append(pnum); 441 features->append(pnum);
449 static hb_feature_t tnum = createFeature('t', 'n', 'u', 'm', 1); 442 static hb_feature_t tnum = createFeature(HB_TAG('t', 'n', 'u', 'm'), 1);
450 if (description.variantNumeric().numericSpacingValue() == 443 if (description.variantNumeric().numericSpacingValue() ==
451 FontVariantNumeric::TabularNums) 444 FontVariantNumeric::TabularNums)
452 features->append(tnum); 445 features->append(tnum);
453 446
454 static hb_feature_t afrc = createFeature('a', 'f', 'r', 'c', 1); 447 static hb_feature_t afrc = createFeature(HB_TAG('a', 'f', 'r', 'c'), 1);
455 if (description.variantNumeric().numericFractionValue() == 448 if (description.variantNumeric().numericFractionValue() ==
456 FontVariantNumeric::StackedFractions) 449 FontVariantNumeric::StackedFractions)
457 features->append(afrc); 450 features->append(afrc);
458 static hb_feature_t frac = createFeature('f', 'r', 'a', 'c', 1); 451 static hb_feature_t frac = createFeature(HB_TAG('f', 'r', 'a', 'c'), 1);
459 if (description.variantNumeric().numericFractionValue() == 452 if (description.variantNumeric().numericFractionValue() ==
460 FontVariantNumeric::DiagonalFractions) 453 FontVariantNumeric::DiagonalFractions)
461 features->append(frac); 454 features->append(frac);
462 455
463 static hb_feature_t ordn = createFeature('o', 'r', 'd', 'n', 1); 456 static hb_feature_t ordn = createFeature(HB_TAG('o', 'r', 'd', 'n'), 1);
464 if (description.variantNumeric().ordinalValue() == 457 if (description.variantNumeric().ordinalValue() ==
465 FontVariantNumeric::OrdinalOn) 458 FontVariantNumeric::OrdinalOn)
466 features->append(ordn); 459 features->append(ordn);
467 460
468 static hb_feature_t zero = createFeature('z', 'e', 'r', 'o', 1); 461 static hb_feature_t zero = createFeature(HB_TAG('z', 'e', 'r', 'o'), 1);
469 if (description.variantNumeric().slashedZeroValue() == 462 if (description.variantNumeric().slashedZeroValue() ==
470 FontVariantNumeric::SlashedZeroOn) 463 FontVariantNumeric::SlashedZeroOn)
471 features->append(zero); 464 features->append(zero);
472 465
473 FontFeatureSettings* settings = description.featureSettings(); 466 FontFeatureSettings* settings = description.featureSettings();
474 if (!settings) 467 if (!settings)
475 return; 468 return;
476 469
477 // TODO(drott): crbug.com/450619 Implement feature resolution instead of 470 // TODO(drott): crbug.com/450619 Implement feature resolution instead of
478 // just appending the font-feature-settings. 471 // just appending the font-feature-settings.
(...skipping 27 matching lines...) Expand all
506 499
507 CapsFeatureSettingsScopedOverlay::CapsFeatureSettingsScopedOverlay( 500 CapsFeatureSettingsScopedOverlay::CapsFeatureSettingsScopedOverlay(
508 FeaturesVector* features, 501 FeaturesVector* features,
509 FontDescription::FontVariantCaps variantCaps) 502 FontDescription::FontVariantCaps variantCaps)
510 : m_features(features), m_countFeatures(0) { 503 : m_features(features), m_countFeatures(0) {
511 overlayCapsFeatures(variantCaps); 504 overlayCapsFeatures(variantCaps);
512 } 505 }
513 506
514 void CapsFeatureSettingsScopedOverlay::overlayCapsFeatures( 507 void CapsFeatureSettingsScopedOverlay::overlayCapsFeatures(
515 FontDescription::FontVariantCaps variantCaps) { 508 FontDescription::FontVariantCaps variantCaps) {
516 static hb_feature_t smcp = createFeature('s', 'm', 'c', 'p', 1); 509 static hb_feature_t smcp = createFeature(HB_TAG('s', 'm', 'c', 'p'), 1);
517 static hb_feature_t pcap = createFeature('p', 'c', 'a', 'p', 1); 510 static hb_feature_t pcap = createFeature(HB_TAG('p', 'c', 'a', 'p'), 1);
518 static hb_feature_t c2sc = createFeature('c', '2', 's', 'c', 1); 511 static hb_feature_t c2sc = createFeature(HB_TAG('c', '2', 's', 'c'), 1);
519 static hb_feature_t c2pc = createFeature('c', '2', 'p', 'c', 1); 512 static hb_feature_t c2pc = createFeature(HB_TAG('c', '2', 'p', 'c'), 1);
520 static hb_feature_t unic = createFeature('u', 'n', 'i', 'c', 1); 513 static hb_feature_t unic = createFeature(HB_TAG('u', 'n', 'i', 'c'), 1);
521 static hb_feature_t titl = createFeature('t', 'i', 't', 'l', 1); 514 static hb_feature_t titl = createFeature(HB_TAG('t', 'i', 't', 'l'), 1);
522 if (variantCaps == FontDescription::SmallCaps || 515 if (variantCaps == FontDescription::SmallCaps ||
523 variantCaps == FontDescription::AllSmallCaps) { 516 variantCaps == FontDescription::AllSmallCaps) {
524 prependCounting(smcp); 517 prependCounting(smcp);
525 if (variantCaps == FontDescription::AllSmallCaps) { 518 if (variantCaps == FontDescription::AllSmallCaps) {
526 prependCounting(c2sc); 519 prependCounting(c2sc);
527 } 520 }
528 } 521 }
529 if (variantCaps == FontDescription::PetiteCaps || 522 if (variantCaps == FontDescription::PetiteCaps ||
530 variantCaps == FontDescription::AllPetiteCaps) { 523 variantCaps == FontDescription::AllPetiteCaps) {
531 prependCounting(pcap); 524 prependCounting(pcap);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 segmentRange.script, !fallbackIterator->hasNext())) 668 segmentRange.script, !fallbackIterator->hasNext()))
676 DLOG(ERROR) << "Shape result extraction failed."; 669 DLOG(ERROR) << "Shape result extraction failed.";
677 670
678 hb_buffer_reset(harfBuzzBuffer.get()); 671 hb_buffer_reset(harfBuzzBuffer.get());
679 } 672 }
680 } 673 }
681 return result.release(); 674 return result.release();
682 } 675 }
683 676
684 } // namespace blink 677 } // 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