OLD | NEW |
---|---|
1 /* | 1 /* |
2 * (C) 1999 Lars Knoll (knoll@kde.org) | 2 * (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 return -1; | 322 return -1; |
323 } | 323 } |
324 | 324 |
325 static Color textColorForWhiteBackground(Color textColor) | 325 static Color textColorForWhiteBackground(Color textColor) |
326 { | 326 { |
327 int distanceFromWhite = differenceSquared(textColor, Color::white); | 327 int distanceFromWhite = differenceSquared(textColor, Color::white); |
328 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; | 328 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; |
329 return distanceFromWhite > 65025 ? textColor : textColor.dark(); | 329 return distanceFromWhite > 65025 ? textColor : textColor.dark(); |
330 } | 330 } |
331 | 331 |
332 static void updateGraphicsContext(GraphicsContext* context, const Color& fillCol or, const Color& strokeColor, float strokeThickness) | |
333 { | |
334 TextDrawingModeFlags mode = context->textDrawingMode(); | |
335 if (strokeThickness > 0) { | |
336 TextDrawingModeFlags newMode = mode | TextModeStroke; | |
337 if (mode != newMode) { | |
338 context->setTextDrawingMode(newMode); | |
339 mode = newMode; | |
340 } | |
341 } | |
342 | |
343 if (mode & TextModeFill && fillColor != context->fillColor()) | |
344 context->setFillColor(fillColor); | |
345 | |
346 if (mode & TextModeStroke) { | |
347 if (strokeColor != context->strokeColor()) | |
348 context->setStrokeColor(strokeColor); | |
349 if (strokeThickness != context->strokeThickness()) | |
350 context->setStrokeThickness(strokeThickness); | |
351 } | |
352 } | |
353 | |
354 bool InlineTextBox::isLineBreak() const | 332 bool InlineTextBox::isLineBreak() const |
355 { | 333 { |
356 return renderer().isBR() || (renderer().style()->preserveNewline() && len() == 1 && (*renderer().text().impl())[start()] == '\n'); | 334 return renderer().isBR() || (renderer().style()->preserveNewline() && len() == 1 && (*renderer().text().impl())[start()] == '\n'); |
357 } | 335 } |
358 | 336 |
359 bool InlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated Offset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) | 337 bool InlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated Offset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) |
360 { | 338 { |
361 if (isLineBreak()) | 339 if (isLineBreak()) |
362 return false; | 340 return false; |
363 | 341 |
364 FloatPoint boxOrigin = locationIncludingFlipping(); | 342 FloatPoint boxOrigin = locationIncludingFlipping(); |
365 boxOrigin.moveBy(accumulatedOffset); | 343 boxOrigin.moveBy(accumulatedOffset); |
366 FloatRect rect(boxOrigin, size()); | 344 FloatRect rect(boxOrigin, size()); |
367 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l ocationInContainer.intersects(rect)) { | 345 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l ocationInContainer.intersects(rect)) { |
368 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset))); | 346 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset))); |
369 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect)) | 347 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect)) |
370 return true; | 348 return true; |
371 } | 349 } |
372 return false; | 350 return false; |
373 } | 351 } |
374 | 352 |
375 static void paintTextWithShadows(GraphicsContext* context, | |
376 const Font& font, const TextRun& textRun, | |
377 const AtomicString& emphasisMark, int emphasisMarkOffset, | |
378 int startOffset, int endOffset, int truncationPoint, | |
379 const FloatPoint& textOrigin, const FloatRect& boxRect, | |
380 const ShadowList* shadowList, bool horizontal) | |
381 { | |
382 // Text shadows are disabled when printing. http://crbug.com/258321 | |
383 bool hasShadow = shadowList && !context->printing(); | |
384 if (hasShadow) | |
385 context->setDrawLooper(shadowList->createDrawLooper(DrawLooperBuilder::S hadowIgnoresAlpha, horizontal)); | |
386 | |
387 TextRunPaintInfo textRunPaintInfo(textRun); | |
388 textRunPaintInfo.bounds = boxRect; | |
389 if (startOffset <= endOffset) { | |
390 textRunPaintInfo.from = startOffset; | |
391 textRunPaintInfo.to = endOffset; | |
392 if (emphasisMark.isEmpty()) | |
393 context->drawText(font, textRunPaintInfo, textOrigin); | |
394 else | |
395 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, tex tOrigin + IntSize(0, emphasisMarkOffset)); | |
396 } else { | |
397 if (endOffset > 0) { | |
398 textRunPaintInfo.from = 0; | |
399 textRunPaintInfo.to = endOffset; | |
400 if (emphasisMark.isEmpty()) | |
401 context->drawText(font, textRunPaintInfo, textOrigin); | |
402 else | |
403 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset)); | |
404 } | |
405 if (startOffset < truncationPoint) { | |
406 textRunPaintInfo.from = startOffset; | |
407 textRunPaintInfo.to = truncationPoint; | |
408 if (emphasisMark.isEmpty()) | |
409 context->drawText(font, textRunPaintInfo, textOrigin); | |
410 else | |
411 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset)); | |
412 } | |
413 } | |
414 | |
415 if (hasShadow) | |
416 context->clearDrawLooper(); | |
417 } | |
418 | |
419 static void paintEmphasisMark(GraphicsContext* context, | |
420 const AtomicString& emphasisMark, int emphasisMarkOffset, | |
421 int startOffset, int endOffset, int paintRunLength, | |
422 const Font& font, Color emphasisMarkColor, Color textStrokeColor, float text StrokeWidth, const ShadowList* textShadow, | |
423 RenderCombineText* combinedText, const TextRun& textRun, | |
424 const FloatPoint& textOrigin, const FloatRect& boxRect, bool horizontal) | |
425 { | |
426 ASSERT(!emphasisMark.isEmpty()); | |
427 updateGraphicsContext(context, emphasisMarkColor, textStrokeColor, textStrok eWidth); | |
428 | |
429 if (combinedText) { | |
430 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&object ReplacementCharacter, 1)); | |
431 FloatPoint emphasisMarkTextOrigin(boxRect.x() + boxRect.width() / 2, box Rect.y() + font.fontMetrics().ascent()); | |
432 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Clock wise)); | |
433 paintTextWithShadows(context, combinedText->originalFont(), objectReplac ementCharacterTextRun, emphasisMark, emphasisMarkOffset, 0, 1, 1, emphasisMarkTe xtOrigin, boxRect, textShadow, horizontal); | |
434 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Count erclockwise)); | |
435 } else { | |
436 paintTextWithShadows(context, font, textRun, emphasisMark, emphasisMarkO ffset, startOffset, endOffset, paintRunLength, textOrigin, boxRect, textShadow, horizontal); | |
437 } | |
438 } | |
439 | |
440 bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi tion& emphasisPosition) const | 353 bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi tion& emphasisPosition) const |
441 { | 354 { |
442 // This function returns true if there are text emphasis marks and they are suppressed by ruby text. | 355 // This function returns true if there are text emphasis marks and they are suppressed by ruby text. |
443 if (style->textEmphasisMark() == TextEmphasisMarkNone) | 356 if (style->textEmphasisMark() == TextEmphasisMarkNone) |
444 return false; | 357 return false; |
445 | 358 |
446 emphasisPosition = style->textEmphasisPosition(); | 359 emphasisPosition = style->textEmphasisPosition(); |
447 if (emphasisPosition == TextEmphasisPositionUnder) | 360 if (emphasisPosition == TextEmphasisPositionUnder) |
448 return true; // Ruby text is always over, so it cannot suppress emphasis marks under. | 361 return true; // Ruby text is always over, so it cannot suppress emphasis marks under. |
449 | 362 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 } | 449 } |
537 | 450 |
538 // Text shadows are disabled when printing. http://crbug.com/258321 | 451 // Text shadows are disabled when printing. http://crbug.com/258321 |
539 if (isPrinting) | 452 if (isPrinting) |
540 selectionStyle.shadow = 0; | 453 selectionStyle.shadow = 0; |
541 } | 454 } |
542 | 455 |
543 return selectionStyle; | 456 return selectionStyle; |
544 } | 457 } |
545 | 458 |
459 void updateGraphicsContext(GraphicsContext* context, const TextPaintingStyle& te xtStyle, bool horizontal, GraphicsContextStateSaver* stateSaver = 0) | |
460 { | |
461 TextDrawingModeFlags mode = context->textDrawingMode(); | |
462 if (textStyle.strokeWidth > 0) { | |
463 TextDrawingModeFlags newMode = mode | TextModeStroke; | |
464 if (mode != newMode) { | |
465 if (stateSaver) { | |
f(malita)
2014/08/20 20:55:40
Nit: I think all callers pass a statesaver now. In
jbroman
2014/08/20 21:03:23
Done.
| |
466 stateSaver->save(); | |
467 stateSaver = 0; | |
468 } | |
469 context->setTextDrawingMode(newMode); | |
470 mode = newMode; | |
471 } | |
472 } | |
473 | |
474 if (mode & TextModeFill && textStyle.fillColor != context->fillColor()) | |
475 context->setFillColor(textStyle.fillColor); | |
476 | |
477 if (mode & TextModeStroke) { | |
478 if (textStyle.strokeColor != context->strokeColor()) | |
479 context->setStrokeColor(textStyle.strokeColor); | |
480 if (textStyle.strokeWidth != context->strokeThickness()) | |
481 context->setStrokeThickness(textStyle.strokeWidth); | |
482 } | |
483 | |
484 // Text shadows are disabled when printing. http://crbug.com/258321 | |
485 if (textStyle.shadow && !context->printing()) { | |
486 if (stateSaver) { | |
487 stateSaver->save(); | |
488 stateSaver = 0; | |
489 } | |
490 context->setDrawLooper(textStyle.shadow->createDrawLooper(DrawLooperBuil der::ShadowIgnoresAlpha, horizontal)); | |
491 } | |
492 } | |
493 | |
494 void paintText(GraphicsContext* context, | |
495 const Font& font, const TextRun& textRun, | |
496 const AtomicString& emphasisMark, int emphasisMarkOffset, | |
497 int startOffset, int endOffset, int truncationPoint, | |
498 const FloatPoint& textOrigin, const FloatRect& boxRect) | |
499 { | |
500 TextRunPaintInfo textRunPaintInfo(textRun); | |
501 textRunPaintInfo.bounds = boxRect; | |
502 if (startOffset <= endOffset) { | |
503 textRunPaintInfo.from = startOffset; | |
504 textRunPaintInfo.to = endOffset; | |
505 if (emphasisMark.isEmpty()) | |
506 context->drawText(font, textRunPaintInfo, textOrigin); | |
507 else | |
508 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, tex tOrigin + IntSize(0, emphasisMarkOffset)); | |
509 } else { | |
510 if (endOffset > 0) { | |
511 textRunPaintInfo.from = 0; | |
512 textRunPaintInfo.to = endOffset; | |
513 if (emphasisMark.isEmpty()) | |
514 context->drawText(font, textRunPaintInfo, textOrigin); | |
515 else | |
516 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset)); | |
517 } | |
518 if (startOffset < truncationPoint) { | |
519 textRunPaintInfo.from = startOffset; | |
520 textRunPaintInfo.to = truncationPoint; | |
521 if (emphasisMark.isEmpty()) | |
522 context->drawText(font, textRunPaintInfo, textOrigin); | |
523 else | |
524 context->drawEmphasisMarks(font, textRunPaintInfo, emphasisMark, textOrigin + IntSize(0, emphasisMarkOffset)); | |
525 } | |
526 } | |
527 } | |
528 | |
529 inline void paintEmphasisMark(GraphicsContext* context, | |
530 const AtomicString& emphasisMark, int emphasisMarkOffset, | |
531 int startOffset, int endOffset, int paintRunLength, | |
532 const Font& font, RenderCombineText* combinedText, const TextRun& textRun, | |
533 const FloatPoint& textOrigin, const FloatRect& boxRect) | |
534 { | |
535 ASSERT(!emphasisMark.isEmpty()); | |
536 | |
537 if (combinedText) { | |
538 DEFINE_STATIC_LOCAL(TextRun, objectReplacementCharacterTextRun, (&object ReplacementCharacter, 1)); | |
539 FloatPoint emphasisMarkTextOrigin(boxRect.x() + boxRect.width() / 2, box Rect.y() + font.fontMetrics().ascent()); | |
540 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Clock wise)); | |
541 paintText(context, combinedText->originalFont(), objectReplacementCharac terTextRun, emphasisMark, emphasisMarkOffset, 0, 1, 1, emphasisMarkTextOrigin, b oxRect); | |
542 context->concatCTM(InlineTextBox::rotation(boxRect, InlineTextBox::Count erclockwise)); | |
543 } else { | |
544 paintText(context, font, textRun, emphasisMark, emphasisMarkOffset, star tOffset, endOffset, paintRunLength, textOrigin, boxRect); | |
545 } | |
546 } | |
547 | |
548 void paintTextWithEmphasisMark( | |
549 GraphicsContext* context, const Font& font, const TextPaintingStyle& textSty le, const TextRun& textRun, | |
550 const AtomicString& emphasisMark, int emphasisMarkOffset, int startOffset, i nt endOffset, int length, | |
551 RenderCombineText* combinedText, const FloatPoint& textOrigin, const FloatRe ct& boxRect, bool horizontal) | |
552 { | |
553 GraphicsContextStateSaver stateSaver(*context, false); | |
554 updateGraphicsContext(context, textStyle, horizontal, &stateSaver); | |
555 paintText(context, font, textRun, nullAtom, 0, startOffset, endOffset, lengt h, textOrigin, boxRect); | |
556 | |
557 if (!emphasisMark.isEmpty()) { | |
558 if (textStyle.emphasisMarkColor != textStyle.fillColor) | |
559 context->setFillColor(textStyle.emphasisMarkColor); | |
560 paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, startOffset , endOffset, length, font, combinedText, textRun, textOrigin, boxRect); | |
561 } | |
562 } | |
563 | |
546 } // namespace | 564 } // namespace |
547 | 565 |
548 void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) | 566 void InlineTextBox::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset, LayoutUnit /*lineTop*/, LayoutUnit /*lineBottom*/) |
549 { | 567 { |
550 if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(&renderer()) || render er().style()->visibility() != VISIBLE | 568 if (isLineBreak() || !paintInfo.shouldPaintWithinRoot(&renderer()) || render er().style()->visibility() != VISIBLE |
551 || m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutli ne || !m_len) | 569 || m_truncation == cFullTruncation || paintInfo.phase == PaintPhaseOutli ne || !m_len) |
552 return; | 570 return; |
553 | 571 |
554 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP haseChildOutlines); | 572 ASSERT(paintInfo.phase != PaintPhaseSelfOutline && paintInfo.phase != PaintP haseChildOutlines); |
555 | 573 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fon tMetrics().descent() + font.emphasisMarkAscent(emphasisMark); | 698 emphasisMarkOffset = emphasisMarkPosition == TextEmphasisPositionOver ? -font.fontMetrics().ascent() - font.emphasisMarkDescent(emphasisMark) : font.fon tMetrics().descent() + font.emphasisMarkAscent(emphasisMark); |
681 | 699 |
682 if (!paintSelectedTextOnly) { | 700 if (!paintSelectedTextOnly) { |
683 // FIXME: Truncate right-to-left text correctly. | 701 // FIXME: Truncate right-to-left text correctly. |
684 int startOffset = 0; | 702 int startOffset = 0; |
685 int endOffset = length; | 703 int endOffset = length; |
686 if (paintSelectedTextSeparately && ePos > sPos) { | 704 if (paintSelectedTextSeparately && ePos > sPos) { |
687 startOffset = ePos; | 705 startOffset = ePos; |
688 endOffset = sPos; | 706 endOffset = sPos; |
689 } | 707 } |
690 | 708 paintTextWithEmphasisMark(context, font, textStyle, textRun, emphasisMar k, emphasisMarkOffset, startOffset, endOffset, length, combinedText, textOrigin, boxRect, isHorizontal()); |
691 // For stroked painting, we have to change the text drawing mode. It's probably dangerous to leave that mutated as a side | |
692 // effect, so only when we know we're stroking, do a save/restore. | |
693 GraphicsContextStateSaver stateSaver(*context, textStyle.strokeWidth > 0 ); | |
694 | |
695 updateGraphicsContext(context, textStyle.fillColor, textStyle.strokeColo r, textStyle.strokeWidth); | |
696 paintTextWithShadows(context, font, textRun, nullAtom, 0, startOffset, e ndOffset, length, textOrigin, boxRect, textStyle.shadow, isHorizontal()); | |
697 | |
698 if (!emphasisMark.isEmpty()) | |
699 paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, startOf fset, endOffset, length, font, textStyle.emphasisMarkColor, textStyle.strokeColo r, textStyle.strokeWidth, textStyle.shadow, combinedText, textRun, textOrigin, b oxRect, isHorizontal()); | |
700 } | 709 } |
701 | 710 |
702 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { | 711 if ((paintSelectedTextOnly || paintSelectedTextSeparately) && sPos < ePos) { |
703 // paint only the text that is selected | 712 // paint only the text that is selected |
704 GraphicsContextStateSaver stateSaver(*context, selectionStyle.strokeWidt h > 0); | 713 paintTextWithEmphasisMark(context, font, selectionStyle, textRun, emphas isMark, emphasisMarkOffset, sPos, ePos, length, combinedText, textOrigin, boxRec t, isHorizontal()); |
705 | |
706 updateGraphicsContext(context, selectionStyle.fillColor, selectionStyle. strokeColor, selectionStyle.strokeWidth); | |
707 paintTextWithShadows(context, font, textRun, nullAtom, 0, sPos, ePos, le ngth, textOrigin, boxRect, selectionStyle.shadow, isHorizontal()); | |
708 | |
709 if (!emphasisMark.isEmpty()) | |
710 paintEmphasisMark(context, emphasisMark, emphasisMarkOffset, sPos, e Pos, length, font, selectionStyle.emphasisMarkColor, selectionStyle.strokeColor, textStyle.strokeWidth, selectionStyle.shadow, combinedText, textRun, textOrigin , boxRect, isHorizontal()); | |
711 } | 714 } |
712 | 715 |
713 // Paint decorations | 716 // Paint decorations |
714 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); | 717 TextDecoration textDecorations = styleToUse->textDecorationsInEffect(); |
715 if (textDecorations != TextDecorationNone && paintInfo.phase != PaintPhaseSe lection) { | 718 if (textDecorations != TextDecorationNone && !paintSelectedTextOnly) { |
716 updateGraphicsContext(context, textStyle.fillColor, textStyle.strokeColo r, textStyle.strokeWidth); | 719 GraphicsContextStateSaver stateSaver(*context, false); |
720 updateGraphicsContext(context, textStyle, isHorizontal(), &stateSaver); | |
717 if (combinedText) | 721 if (combinedText) |
718 context->concatCTM(rotation(boxRect, Clockwise)); | 722 context->concatCTM(rotation(boxRect, Clockwise)); |
719 paintDecoration(context, boxOrigin, textDecorations, textStyle.shadow); | 723 paintDecoration(context, boxOrigin, textDecorations); |
720 if (combinedText) | 724 if (combinedText) |
721 context->concatCTM(rotation(boxRect, Counterclockwise)); | 725 context->concatCTM(rotation(boxRect, Counterclockwise)); |
722 } | 726 } |
723 | 727 |
724 if (paintInfo.phase == PaintPhaseForeground) { | 728 if (paintInfo.phase == PaintPhaseForeground) { |
725 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); | 729 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); |
726 | 730 |
727 // Paint custom underlines for compositions. | 731 // Paint custom underlines for compositions. |
728 if (useCustomUnderlines) { | 732 if (useCustomUnderlines) { |
729 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines(); | 733 const Vector<CompositionUnderline>& underlines = renderer().frame()- >inputMethodController().customCompositionUnderlines(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
768 | 772 |
769 Color c = renderer().selectionBackgroundColor(); | 773 Color c = renderer().selectionBackgroundColor(); |
770 if (!c.alpha()) | 774 if (!c.alpha()) |
771 return; | 775 return; |
772 | 776 |
773 // If the text color ends up being the same as the selection background, inv ert the selection | 777 // If the text color ends up being the same as the selection background, inv ert the selection |
774 // background. | 778 // background. |
775 if (textColor == c) | 779 if (textColor == c) |
776 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); | 780 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); |
777 | 781 |
778 | |
779 // If the text is truncated, let the thing being painted in the truncation | 782 // If the text is truncated, let the thing being painted in the truncation |
780 // draw its own highlight. | 783 // draw its own highlight. |
781 int length = m_truncation != cNoTruncation ? m_truncation : m_len; | 784 int length = m_truncation != cNoTruncation ? m_truncation : m_len; |
782 StringView string = renderer().text().createView(); | 785 StringView string = renderer().text().createView(); |
783 | 786 |
784 if (string.length() != static_cast<unsigned>(length) || m_start) | 787 if (string.length() != static_cast<unsigned>(length) || m_start) |
785 string.narrow(m_start, length); | 788 string.narrow(m_start, length); |
786 | 789 |
787 StringBuilder charactersWithHyphen; | 790 StringBuilder charactersWithHyphen; |
788 bool respectHyphen = ePos == length && hasHyphen(); | 791 bool respectHyphen = ePos == length && hasHyphen(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 context->setShouldAntialias(antialiasDecoration); | 1038 context->setShouldAntialias(antialiasDecoration); |
1036 // Fall through | 1039 // Fall through |
1037 default: | 1040 default: |
1038 context->drawLineForText(start, width, isPrinting); | 1041 context->drawLineForText(start, width, isPrinting); |
1039 | 1042 |
1040 if (decoration.style == TextDecorationStyleDouble) | 1043 if (decoration.style == TextDecorationStyleDouble) |
1041 context->drawLineForText(start + FloatPoint(0, doubleOffset), width, isPrinting); | 1044 context->drawLineForText(start + FloatPoint(0, doubleOffset), width, isPrinting); |
1042 } | 1045 } |
1043 } | 1046 } |
1044 | 1047 |
1045 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco, const ShadowList* shadowList) | 1048 void InlineTextBox::paintDecoration(GraphicsContext* context, const FloatPoint& boxOrigin, TextDecoration deco) |
1046 { | 1049 { |
1047 GraphicsContextStateSaver stateSaver(*context); | 1050 GraphicsContextStateSaver stateSaver(*context); |
1048 | 1051 |
1049 if (m_truncation == cFullTruncation) | 1052 if (m_truncation == cFullTruncation) |
1050 return; | 1053 return; |
1051 | 1054 |
1052 FloatPoint localOrigin = boxOrigin; | 1055 FloatPoint localOrigin = boxOrigin; |
1053 | 1056 |
1054 float width = m_logicalWidth; | 1057 float width = m_logicalWidth; |
1055 if (m_truncation != cNoTruncation) { | 1058 if (m_truncation != cNoTruncation) { |
1056 width = renderer().width(m_start, m_truncation, textPos(), isLeftToRight Direction() ? LTR : RTL, isFirstLineStyle()); | 1059 width = renderer().width(m_start, m_truncation, textPos(), isLeftToRight Direction() ? LTR : RTL, isFirstLineStyle()); |
1057 if (!isLeftToRightDirection()) | 1060 if (!isLeftToRightDirection()) |
1058 localOrigin.move(m_logicalWidth - width, 0); | 1061 localOrigin.move(m_logicalWidth - width, 0); |
1059 } | 1062 } |
1060 | 1063 |
1061 // Get the text decoration colors. | 1064 // Get the text decoration colors. |
1062 RenderObject::AppliedTextDecoration underline, overline, linethrough; | 1065 RenderObject::AppliedTextDecoration underline, overline, linethrough; |
1063 | |
1064 renderer().getTextDecorations(deco, underline, overline, linethrough, true); | 1066 renderer().getTextDecorations(deco, underline, overline, linethrough, true); |
1065 if (isFirstLineStyle()) | 1067 if (isFirstLineStyle()) |
1066 renderer().getTextDecorations(deco, underline, overline, linethrough, tr ue, true); | 1068 renderer().getTextDecorations(deco, underline, overline, linethrough, tr ue, true); |
1067 | 1069 |
1068 // Use a special function for underlines to get the positioning exactly righ t. | 1070 // Use a special function for underlines to get the positioning exactly righ t. |
1069 bool isPrinting = renderer().document().printing(); | 1071 bool isPrinting = renderer().document().printing(); |
1070 | 1072 |
1071 bool linesAreOpaque = !isPrinting && (!(deco & TextDecorationUnderline) || u nderline.color.alpha() == 255) && (!(deco & TextDecorationOverline) || overline. color.alpha() == 255) && (!(deco & TextDecorationLineThrough) || linethrough.col or.alpha() == 255); | |
1072 | |
1073 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); | 1073 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); |
1074 int baseline = styleToUse->fontMetrics().ascent(); | 1074 int baseline = styleToUse->fontMetrics().ascent(); |
1075 | 1075 |
1076 size_t shadowCount = shadowList ? shadowList->shadows().size() : 0; | |
1077 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px. | 1076 // Set the thick of the line to be 10% (or something else ?)of the computed font size and not less than 1px. |
1078 // Using computedFontSize should take care of zoom as well. | 1077 // Using computedFontSize should take care of zoom as well. |
1079 | 1078 |
1080 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method. | 1079 // Update Underline thickness, in case we have Faulty Font Metrics calculati ng underline thickness by old method. |
1081 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness (); | 1080 float textDecorationThickness = styleToUse->fontMetrics().underlineThickness (); |
1082 int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5); | 1081 int fontHeightInt = (int)(styleToUse->fontMetrics().floatHeight() + 0.5); |
1083 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1))) | 1082 if ((textDecorationThickness == 0.f) || (textDecorationThickness >= (fontHei ghtInt >> 1))) |
1084 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f); | 1083 textDecorationThickness = std::max(1.f, styleToUse->computedFontSize() / 10.f); |
1085 | 1084 |
1086 context->setStrokeThickness(textDecorationThickness); | 1085 context->setStrokeThickness(textDecorationThickness); |
1087 | 1086 |
1088 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style) | 1087 bool antialiasDecoration = shouldSetDecorationAntialias(overline.style, unde rline.style, linethrough.style) |
1089 && RenderBoxModelObject::shouldAntialiasLines(context); | 1088 && RenderBoxModelObject::shouldAntialiasLines(context); |
1090 | 1089 |
1091 float extraOffset = 0; | 1090 // Offset between lines - always non-zero, so lines never cross each other. |
1092 if (!linesAreOpaque && shadowCount > 1) { | 1091 float doubleOffset = textDecorationThickness + 1.f; |
1093 FloatRect clipRect(localOrigin, FloatSize(width, baseline + 2)); | 1092 |
1094 for (size_t i = shadowCount; i--; ) { | 1093 if (deco & TextDecorationUnderline) { |
1095 const ShadowData& s = shadowList->shadows()[i]; | 1094 const int underlineOffset = computeUnderlineOffset(styleToUse->textUnder linePosition(), styleToUse->fontMetrics(), this, textDecorationThickness); |
1096 FloatRect shadowRect(localOrigin, FloatSize(width, baseline + 2)); | 1095 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlineOff set), width, doubleOffset, 1, underline, textDecorationThickness, antialiasDecor ation, isPrinting); |
1097 shadowRect.inflate(s.blur()); | |
1098 float shadowX = isHorizontal() ? s.x() : s.y(); | |
1099 float shadowY = isHorizontal() ? s.y() : -s.x(); | |
1100 shadowRect.move(shadowX, shadowY); | |
1101 clipRect.unite(shadowRect); | |
1102 extraOffset = std::max(extraOffset, std::max(0.0f, shadowY) + s.blur ()); | |
1103 } | |
1104 context->clip(clipRect); | |
1105 extraOffset += baseline + 2; | |
1106 localOrigin.move(0, extraOffset); | |
1107 } | 1096 } |
1108 | 1097 if (deco & TextDecorationOverline) { |
1109 for (size_t i = std::max(static_cast<size_t>(1), shadowCount); i--; ) { | 1098 paintAppliedDecoration(context, localOrigin, width, -doubleOffset, 1, ov erline, textDecorationThickness, antialiasDecoration, isPrinting); |
1110 // Even if we have no shadows, we still want to run the code below this once. | 1099 } |
1111 if (i < shadowCount) { | 1100 if (deco & TextDecorationLineThrough) { |
1112 if (!i) { | 1101 const float lineThroughOffset = 2 * baseline / 3; |
1113 // The last set of lines paints normally inside the clip. | 1102 paintAppliedDecoration(context, localOrigin + FloatPoint(0, lineThroughO ffset), width, doubleOffset, 0, linethrough, textDecorationThickness, antialiasD ecoration, isPrinting); |
1114 localOrigin.move(0, -extraOffset); | |
1115 extraOffset = 0; | |
1116 } | |
1117 const ShadowData& shadow = shadowList->shadows()[i]; | |
1118 float shadowX = isHorizontal() ? shadow.x() : shadow.y(); | |
1119 float shadowY = isHorizontal() ? shadow.y() : -shadow.x(); | |
1120 context->setShadow(FloatSize(shadowX, shadowY - extraOffset), shadow .blur(), shadow.color()); | |
1121 } | |
1122 | |
1123 // Offset between lines - always non-zero, so lines never cross each oth er. | |
1124 float doubleOffset = textDecorationThickness + 1.f; | |
1125 | |
1126 if (deco & TextDecorationUnderline) { | |
1127 const int underlineOffset = computeUnderlineOffset(styleToUse->textU nderlinePosition(), styleToUse->fontMetrics(), this, textDecorationThickness); | |
1128 paintAppliedDecoration(context, localOrigin + FloatPoint(0, underlin eOffset), width, doubleOffset, 1, underline, textDecorationThickness, antialiasD ecoration, isPrinting); | |
1129 } | |
1130 if (deco & TextDecorationOverline) { | |
1131 paintAppliedDecoration(context, localOrigin, width, -doubleOffset, 1 , overline, textDecorationThickness, antialiasDecoration, isPrinting); | |
1132 } | |
1133 if (deco & TextDecorationLineThrough) { | |
1134 const float lineThroughOffset = 2 * baseline / 3; | |
1135 paintAppliedDecoration(context, localOrigin + FloatPoint(0, lineThro ughOffset), width, doubleOffset, 0, linethrough, textDecorationThickness, antial iasDecoration, isPrinting); | |
1136 } | |
1137 } | 1103 } |
1138 } | 1104 } |
1139 | 1105 |
1140 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType) | 1106 static GraphicsContext::DocumentMarkerLineStyle lineStyleForMarkerType(DocumentM arker::MarkerType markerType) |
1141 { | 1107 { |
1142 switch (markerType) { | 1108 switch (markerType) { |
1143 case DocumentMarker::Spelling: | 1109 case DocumentMarker::Spelling: |
1144 return GraphicsContext::DocumentMarkerSpellingLineStyle; | 1110 return GraphicsContext::DocumentMarkerSpellingLineStyle; |
1145 case DocumentMarker::Grammar: | 1111 case DocumentMarker::Grammar: |
1146 return GraphicsContext::DocumentMarkerGrammarLineStyle; | 1112 return GraphicsContext::DocumentMarkerGrammarLineStyle; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1520 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); | 1486 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); |
1521 const int rendererCharacterOffset = 24; | 1487 const int rendererCharacterOffset = 24; |
1522 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1488 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
1523 fputc(' ', stderr); | 1489 fputc(' ', stderr); |
1524 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); | 1490 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); |
1525 } | 1491 } |
1526 | 1492 |
1527 #endif | 1493 #endif |
1528 | 1494 |
1529 } // namespace blink | 1495 } // namespace blink |
OLD | NEW |