|
Lines 301-332
String PrintContext::pageSizeAndMarginsInPixels(Frame* frame, int pageNumber, in
a/Source/WebCore/page/PrintContext.cpp_sec1
|
| 301 |
String::number(marginTop) + ' ' + String::number(marginRight) + ' ' + String::number(marginBottom) + ' ' + String::number(marginLeft); |
301 |
String::number(marginTop) + ' ' + String::number(marginRight) + ' ' + String::number(marginBottom) + ' ' + String::number(marginLeft); |
| 302 |
} |
302 |
} |
| 303 |
|
303 |
|
| 304 |
int PrintContext::numberOfPages(Frame* frame, const FloatSize& pageSizeInPixels) |
304 |
bool PrintContext::beginAndComputePageRectsWithPageSize(Frame& frame, const FloatSize& pageSizeInPixels) |
| 305 |
{ |
305 |
{ |
| 306 |
frame->document()->updateLayout(); |
306 |
if (!frame.document() || !frame.view() || !frame.document()->renderView()) |
|
|
307 |
return false; |
| 307 |
|
308 |
|
| 308 |
FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); |
309 |
frame.document()->updateLayout(); |
| 309 |
PrintContext printContext(frame); |
310 |
|
| 310 |
printContext.begin(pageRect.width(), pageRect.height()); |
311 |
begin(pageSizeInPixels.width(), pageSizeInPixels.height()); |
| 311 |
// Account for shrink-to-fit. |
312 |
// Account for shrink-to-fit. |
| 312 |
FloatSize scaledPageSize = pageSizeInPixels; |
313 |
FloatSize scaledPageSize = pageSizeInPixels; |
| 313 |
scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width()); |
314 |
scaledPageSize.scale(frame.view()->contentsSize().width() / pageSizeInPixels.width()); |
| 314 |
printContext.computePageRectsWithPageSize(scaledPageSize, false); |
315 |
computePageRectsWithPageSize(scaledPageSize, false); |
| 315 |
return printContext.pageCount(); |
316 |
|
|
|
317 |
return true; |
| 316 |
} |
318 |
} |
| 317 |
|
319 |
|
| 318 |
void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels) |
320 |
int PrintContext::numberOfPages(Frame& frame, const FloatSize& pageSizeInPixels) |
| 319 |
{ |
321 |
{ |
| 320 |
if (!frame->document() || !frame->view() || !frame->document()->renderView()) |
322 |
PrintContext printContext(&frame); |
| 321 |
return; |
323 |
if (!printContext.beginAndComputePageRectsWithPageSize(frame, pageSizeInPixels)) |
| 322 |
|
324 |
return -1; |
| 323 |
frame->document()->updateLayout(); |
|
|
| 324 |
|
325 |
|
| 325 |
PrintContext printContext(frame); |
326 |
return printContext.pageCount(); |
| 326 |
printContext.begin(pageSizeInPixels.width(), pageSizeInPixels.height()); |
327 |
} |
| 327 |
|
328 |
|
| 328 |
float pageHeight; |
329 |
void PrintContext::spoolAllPagesWithBoundaries(Frame& frame, GraphicsContext& graphicsContext, const FloatSize& pageSizeInPixels) |
| 329 |
printContext.computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight); |
330 |
{ |
|
|
331 |
PrintContext printContext(&frame); |
| 332 |
if (!printContext.beginAndComputePageRectsWithPageSize(frame, pageSizeInPixels)) |
| 333 |
return; |
| 330 |
|
334 |
|
| 331 |
const float pageWidth = pageSizeInPixels.width(); |
335 |
const float pageWidth = pageSizeInPixels.width(); |
| 332 |
const Vector<IntRect>& pageRects = printContext.pageRects(); |
336 |
const Vector<IntRect>& pageRects = printContext.pageRects(); |
|
Lines 337-354
void PrintContext::spoolAllPagesWithBoundaries(Frame* frame, GraphicsContext& gr
a/Source/WebCore/page/PrintContext.cpp_sec2
|
| 337 |
graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight)); |
341 |
graphicsContext.fillRect(FloatRect(0, 0, pageWidth, totalHeight)); |
| 338 |
|
342 |
|
| 339 |
graphicsContext.save(); |
343 |
graphicsContext.save(); |
|
|
344 |
#if PLATFORM(COCOA) |
| 340 |
graphicsContext.translate(0, totalHeight); |
345 |
graphicsContext.translate(0, totalHeight); |
| 341 |
graphicsContext.scale(FloatSize(1, -1)); |
346 |
graphicsContext.scale(FloatSize(1, -1)); |
|
|
347 |
#endif |
| 342 |
|
348 |
|
| 343 |
int currentHeight = 0; |
349 |
int currentHeight = 0; |
| 344 |
for (size_t pageIndex = 0; pageIndex < pageRects.size(); pageIndex++) { |
350 |
for (size_t pageIndex = 0; pageIndex < pageRects.size(); pageIndex++) { |
| 345 |
// Draw a line for a page boundary if this isn't the first page. |
351 |
// Draw a line for a page boundary if this isn't the first page. |
| 346 |
if (pageIndex > 0) { |
352 |
if (pageIndex > 0) { |
|
|
353 |
#if PLATFORM(COCOA) |
| 354 |
int boundaryLineY = currentHeight; |
| 355 |
#else |
| 356 |
int boundaryLineY = currentHeight - 1; |
| 357 |
#endif |
| 347 |
graphicsContext.save(); |
358 |
graphicsContext.save(); |
| 348 |
graphicsContext.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB); |
359 |
graphicsContext.setStrokeColor(Color(0, 0, 255), ColorSpaceDeviceRGB); |
| 349 |
graphicsContext.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB); |
360 |
graphicsContext.setFillColor(Color(0, 0, 255), ColorSpaceDeviceRGB); |
| 350 |
graphicsContext.drawLine(IntPoint(0, currentHeight), |
361 |
graphicsContext.drawLine(IntPoint(0, boundaryLineY), IntPoint(pageWidth, boundaryLineY)); |
| 351 |
IntPoint(pageWidth, currentHeight)); |
|
|
| 352 |
graphicsContext.restore(); |
362 |
graphicsContext.restore(); |
| 353 |
} |
363 |
} |
| 354 |
|
364 |
|