LayoutImage.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <LibDraw/Font.h>
  2. #include <LibDraw/StylePainter.h>
  3. #include <LibGUI/GPainter.h>
  4. #include <LibHTML/Layout/LayoutImage.h>
  5. LayoutImage::LayoutImage(const HTMLImageElement& element, NonnullRefPtr<StyleProperties> style)
  6. : LayoutReplaced(element, move(style))
  7. {
  8. }
  9. LayoutImage::~LayoutImage()
  10. {
  11. }
  12. void LayoutImage::layout()
  13. {
  14. if (renders_as_alt_text()) {
  15. auto& font = Font::default_font();
  16. rect().set_width(font.width(node().alt()) + 16);
  17. rect().set_height(font.glyph_height() + 16);
  18. }
  19. LayoutReplaced::layout();
  20. }
  21. void LayoutImage::render(RenderingContext& context)
  22. {
  23. if (renders_as_alt_text()) {
  24. context.painter().set_font(Font::default_font());
  25. StylePainter::paint_frame(context.painter(), rect(), FrameShape::Container, FrameShadow::Sunken, 2);
  26. context.painter().draw_text(rect(), node().alt(), TextAlignment::Center, Color::White);
  27. }
  28. LayoutReplaced::render(context);
  29. }
  30. bool LayoutImage::renders_as_alt_text() const
  31. {
  32. return true;
  33. }