Advertisement

11.05.2007 at 08:53PM PST, ID: 22940964
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Calculating text wraps

Asked by M3Mania in PHP Scripting Language, JavaScript, Cascading Style Sheets (CSS)

Tags: , , ,

I am building a system that needs to permit users to lay out some content (text boxes and graphics) in a web browser using javascript and CSS. I need to then convert that layout into a faithful representation in a PDF. The text needs to be a mix of normal, bold, and italic text.

I am currently using a mix of javascript, CSS, and PHP. I can convert the content to PDF using the PHP class in Zend framework. However, I need to figure out the most efficient way to calculate word wraps and convert text sizing from CSS to PDF.

The sizing can be relative because the user will see a fixed box working area. On some screens, it will be bigger than others (due to varying resolutions and screen sizes), but the relative sizes will remain the same in CSS. Therefore, if I use absolute pixel size for both the outer containing box and the font, I should be able to maintain a proper relative size.

Also, within the PDF I can figure out the appropriate font size using the relative pixel sizes of outer bounding box and font. However, in Zend PDF I can render text lines... but not text within a bounding box.  I need an efficient way to translate from CSS to PDF to get similar text wrapping.

One thought is to use a lookup table to calculate the character widths of the Truetype fonts in question, and figure out width from there. We'd have to have a lookup for each character, in each style, for each font used. I'm not sure whether TT fonts use font kerning pairs. If so, the lookup table would have to be even bigger. What a pain.

Because Firefox and other browser already do a bang-up job of calculating text wrap, it would also make sense to figure out how they're doing it and mimic it.

Or, we could do a sample and retry method by creating rendered images of the text in question using PHP. Or we can use the PHP imagettfbbox function (or related functions). The problem is I don't know if they can handle inline calculation of varying fonts (e.g. bold, italic, normal).

I'm hoping someone has had to wrestle with this issue before and can provide a slick answer!Start Free Trial
[+][-]11.05.2007 at 09:11PM PST, ID: 20221503

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, JavaScript, Cascading Style Sheets (CSS)
Tags: calculate, php, boxes, wrapping
Sign Up Now!
Solution Provided By: basicinstinct
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.02.2008 at 12:30AM PDT, ID: 22621926

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]10.06.2008 at 03:46PM PDT, ID: 22655100

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628