コード例 #1
0
function makeSwissQuadCover ({book, fonts, w, h}) {
  const r = new Rune({
    width: w,
    height: h
  })

  const leakBgColor = false // optional

  const paperColor = paperAging(book.year)

  const pattern = random.element(patterns.all)

  const patternGroup = r.group(w / 3, (h - w / 3 * 2) / 2)
  const patternBg = pattern({ book, r, w: w / 3 * 2, h: w / 3 * 2 })
    .addTo(patternGroup)

  let bgColor = new Rune.Color(paperColor[0], paperColor[1], paperColor[2])
  let textColor = '#333333'

  if (leakBgColor) {
    bgColor = patternBg.children[0].state.fill
    textColor = '#FFFFFF'
  }

  // there is no way to clip paths in rune.js so let's crop pattern with 3 quads
  r.rect(0, 0, w / 3, h)
    .stroke(false).fill(bgColor)

  r.rect(w / 3, 0, w / 3 * 2, (h - w / 3 * 2) / 2)
    .stroke(false).fill(bgColor)

  r.rect(w / 3, (h - w / 3 * 2) / 2 + w / 3 * 2, w / 3 * 2, (h - w / 3 * 2) / 2)
    .stroke(false).fill(bgColor)

  const squareSize = w / 3 * 2
  const verticalGap = (h - squareSize) / 2

  const authorFontSize = h * 0.035
  const author = typo.formatAuthorName(book.author)
  const authorBounds = [
    0,
    0,
    w - squareSize,
    verticalGap
  ]

  typo.drawTextInRect({
    r,
    font,
    text: [author.name, author.surname],
    bounds: authorBounds,
    // debug: true,
    fontSize: authorFontSize,
    lineHeight: 1,
    padding: [0.75, 0, 1, 2],
    textAlign: 'right',
    verticalAlign: 'middle',
    textColor: textColor
  })

  const titleFontSize = h * 0.06
  const title = book.title.toUpperCase()
  const titleBounds = [
    w / 3,
    verticalGap + squareSize + h * 0.02,
    squareSize,
    verticalGap
  ]

  typo.drawTextInRect({
    r,
    font,
    text: title,
    bounds: titleBounds,
    // debug: true,
    fontSize: titleFontSize,
    lineHeight: 1,
    padding: [0, 2, 2, 0]
  })

  r.draw()
  return r.el
}
コード例 #2
0
function makeRightLabelCover ({book, fonts, w, h}) {
  const r = new Rune({
    width: w,
    height: h
  })

  const pattern = random.element(patterns.all)

  const patternGroup = r.group(0, 0)
  pattern({ book, r, w, h })
    .addTo(patternGroup)

  let bgColor = '#f5f4ea'
  let textColor = '#333333'

  // there is no way to clip paths in rune.js so let's crop pattern with 3 quads
  r.rect(w * 0.6, 0, w * 0.4, h)
    .stroke(false).fill(bgColor)

  const titleFontSize = h * 0.06
  const title = book.title
  const titleBounds = [
    w * 0.65,
    w * 0.1,
    w * 0.35,
    w * 0.55
  ]

  const titleTextInfo = typo.drawTextInRect({
    r,
    font,
    text: title,
    bounds: titleBounds,
    // debug: true,
    fontSize: titleFontSize,
    lineHeight: 1,
    padding: [0, 1, 1, 0]
  })

  const authorFontSize = Math.min(h * 0.03, titleTextInfo.fontSize * 0.8)
  const author = typo.formatAuthorName(book.author)
  const authorBounds = [
    w * 0.65,
    titleTextInfo.textBounds[1] + titleTextInfo.textBounds[3],
    w * 0.35,
    w * 0.4
  ]

  typo.drawTextInRect({
    r,
    font,
    text: [author.name, author.surname],
    bounds: authorBounds,
    // debug: true,
    fontSize: authorFontSize,
    lineHeight: 1,
    padding: [1.5, 1, 1, 0],
    textColor: textColor
  })

  r.draw()
  return r.el
}