Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Exact graphical equivalence between browsers (especially with fonts)?

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default Exact graphical equivalence between browsers (especially with fonts)?

    Following the information in this thread:
    http://www.dynamicdrive.com/forums/s...t-on-a-webpage
    I now have a working PDF/HTML system so that I can display the same content in each, within the same space. It's working fairly well.


    My new problem is getting browsers to display content identically. Is this doomed to failure?

    The specific problem at the moment, although I wouldn't be surprised by more problems later, is fonts. I've set the fonts in mm, but they're still varying just slightly between browsers. In Safari vs Firefox, once in a while an extra word is cut off at the end of a line, and in the end this changes the length of the text by one or two lines-- changing the page breaks.

    Is there anything I can do about this? Is it even remotely possible to guarantee the exact same dimensions in two browsers?


    My goal is to develop an HTML preview of what will later be generated as PDFs.



    For what it's worth, the PHP PDF extension (mpdf) is working fine, and it seems to be identical to Firefox. So for the moment I'm not worrying about it.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I seriously doubt you'll be able to get pixel-perfect fonts between browsers. Firefox specifically renders fonts differently (heavier) than most other browsers. Further, between operating systems, it's impossible AFAIK.

    microsoft, for example, takes not only a different technical approach than apple, but their approach is philosophically different: ms pushes the font glyphs around to fit onto the screen pixel grid (sharper letters, but less true to the actual glyphs), while apple uses heavy anit-aliasing algorithms to try to preserve the shapes of the glyphs (fuzzier letters, but truer to the font glyphs).

    A good "fallback" might be to offer a PDF preview (most modern browsers have no problem viewing PDFs), though constantly rendering previews might be an increased load on your server.

  3. The Following User Says Thank You to traq For This Useful Post:

    djr33 (10-23-2012)

  4. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I was worried about those things. You mentioned an important point I hadn't thought of, though, about the OS font rendering.

    Hm. Maybe this is impossible. Annoying.


    The entire purpose is to avoid using a PDF. I'm trying to create ebooks that can be viewed as webpages (HTML) or downloaded as PDFs. In order to make the page breaks fall in reasonable places, the PDF's paging must be shown in the HTML.

    I can't actually use PDFs in the webpage because not enough browsers support that and I want people to be able to easily cut and paste text anyway. (And it would be a lot of work for the server. These could be 100 page books with graphics.)


    So... ok... how do PDFs work? They look the same, or at least have the same page-breaking on various OSs? So is there some theoretical way to design HTML to do the same thing? Would it involve manually positioning each letter/word/line? I'm not sure that's actually reasonable for my current project, but I'd like to find some way to do this.

    I don't care about pixel perfect similarity; I care about where things fall on the page. It doesn't need to be identical, but it can't be 1 page for some people and 2 pages for others. I'm not sure if there's any way around getting pixel-level precision then. Maybe/probably not.


    Additionally, though this may no longer be relevant, I can also specifically limit the HTML to only contain certain objects. So I don't need to worry about everything being identical, just that some (important) layout things are.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I hate it but cufon might work for this.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    djr33 (10-23-2012)

  7. #5
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    There are a couple of options mentioned in this stack overflow thread that you could use.

    Quote Originally Posted by djr33 View Post
    I don't care about pixel perfect similarity; I care about where things fall on the page. It doesn't need to be identical, but it can't be 1 page for some people and 2 pages for others. I'm not sure if there's any way around getting pixel-level precision then. Maybe/probably not.
    Something that may help with that; remember to use mono-spaced fonts such as courier new, or <pre> tags.

    another link

    this one mentions cross OS consistency

    If you hadn't realised, the main theme of these is just resetting the css for font sizes, to try and get consistency across browsers and platforms. Yahoo actually use css resets as the basis for their cross-browser consistency.
    Last edited by bernie1227; 10-22-2012 at 08:34 PM.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  8. The Following User Says Thank You to bernie1227 For This Useful Post:

    djr33 (10-23-2012)

  9. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by djr33 View Post
    ... It doesn't need to be identical, but it can't be 1 page for some people and 2 pages for others.
    well... a few ideas:


    1. you could be a little on the restrictive side with widths, margins, and padding in the working (html) version, and then relax them a little when you generate the pdf. You'd have to do some experimenting with what the "best" compromises would be (and you might end up with the opposite problems: two pages in the preview, only one in the pdf).

    2. after rendering the pdf, check that the expected:actual number of pages match. If not, change widths, margins, etc. a little bit until they do. This still puts extra work on your server and sacrifices some control, however...

    3. I don't know if you can programatically (javascript) find the positioning offset of particular letters on the screen. If you can, then you can determine where lines break, and preserve them even when increasing the actual page margins.

  10. The Following User Says Thank You to traq For This Useful Post:

    djr33 (10-23-2012)

  11. #7
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by traq View Post

    3. I don't know if you can programatically (javascript) find the positioning offset of particular letters on the screen. If you can, then you can determine where lines break, and preserve them even when increasing the actual page margins.
    http://jsfiddle.net/cgXa3/4/
    The idea of this one, is to get a letter, wrap it with a span with a class, and then offset it as well as getting its offset and alerting it (note: this jsfiddle is choosing a random letter). It's also quite possible, and a lot easier to do the same thing but have a pre-existing span around specific words and then get the offset.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  12. The Following User Says Thank You to bernie1227 For This Useful Post:

    djr33 (10-23-2012)

  13. #8
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Cool - that's what I was thinking - but I can't think of a way to apply it to what Daniel needs, except to literally loop through every letter, check its position, and then determine which are at the ends of their line. Seems inefficient.

  14. The Following User Says Thank You to traq For This Useful Post:

    djr33 (10-23-2012)

  15. #9
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    46
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    Get the id of the last letter on a page and make sure it stays on the right page?
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  16. The Following User Says Thank You to bernie1227 For This Useful Post:

    djr33 (10-23-2012)

  17. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    actually, I was thinking more like:

    1. start with bigger page margins than you want to end up with (e.g., 1" around the page instead of 3/4")
    2. find the last letter on each line
    3. insert a line break right after it ("hardwrapping" the paragraph, so to speak)
    4. use the (smaller) desired margins for the PDF to ensure everything fits on the page; while the linebreaks will prevent any change in text wrapping.

  18. The Following User Says Thank You to traq For This Useful Post:

    djr33 (10-23-2012)

Similar Threads

  1. Display an image at a exact time of day.
    By Dazzatron in forum PHP
    Replies: 1
    Last Post: 02-10-2012, 02:38 PM
  2. Fonts & Browsers
    By bassa in forum HTML
    Replies: 2
    Last Post: 08-25-2008, 10:35 PM
  3. Searching for exact date
    By revray in forum PHP
    Replies: 1
    Last Post: 02-25-2008, 02:12 AM
  4. Searching an EXACT date
    By revray in forum PHP
    Replies: 7
    Last Post: 02-24-2008, 05:40 AM
  5. exact age calculator
    By xecure in forum JavaScript
    Replies: 1
    Last Post: 10-10-2005, 05:42 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •