DefaultPaperSize

From Apache OpenOffice Wiki
Revision as of 10:45, 13 August 2008 by Caolan (Talk | contribs)

Jump to: navigation, search

Default Paper Size on Linux

In OpenOffice.org VCL has a concept of a default paper size for a printer, and most applications then have a parallel concept of a default paper size for pages in a documents.

The VCL paper size for a printer can be seen in the UI in file->printer settings->properties->paper size The Application paper size for a page can be seen in the UI in e.g. writer from format->page

The VCL paper size doesn't matter greatly as its overridden by most OpenOffice.org applications, only simple applications like Math have no page style to override it.

VCL Default Paper Size

On Linux this default paper size is determined in psprint/source/printer/printerinfomanager.cxx as PrinterInfoManager::initSystemDefaultPaper the algorithm is

  • ask paperconf if it exists
    • paperconf checks $PAPERSIZE as "Letter" vs "A4", falling back to the contents of the file at $PAPERCONF, falling back to the contents of /etc/papersize, falling back to a default of "Letter"
  • otherwise check LC_PAPER and use mapping one
  • otherwise check osl_getProcessLocale and use mapping one
    • osl_getProcessLocale ends up in sal/osl/unx/nlsupport.c taking the value of LC_CTYPE

mapping one

All locales are A4 except for: en_US, en_CA, fr_CA, en

Application Default Paper Size

The default paper size is derived effectively from DefaultLocale by SvxPaperInfo::GetDefaultSvxPaper in svx/source/items/paperinf.cxx using mapping two. DefaultLocale is set during first-start from

  • getLangFromEnvironment in i18npool/source/isolang/inunx.cxx
    • LC_ALL, LC_CTYPE, LANG

mapping two

All locales are A4 except for: en_US, en_CA, fr_CA, es_MX, es_VE

GTK

For comparison gtk has gtk_paper_size_get_default which takes this from the locale as well, using mapping three.

  • LC_PAPER, LC_MESSAGES (gtk/gtkpapersize.c)

mapping three

All locales are A4 except for: en_US, en_CA, es_PR, es_US


CLDR

At unicode.org the only locales listed as using Letter are the US and Canada. (Puerto Rico, Mexico, Venezuela are all listed as A4). While Wikipedia also agrees that only the US and Canada officially don't use A4 but that in Mexico, Colombia, Chile and the Philippines Letter is also commonly used. Meanwhile at Microsoft the list of Letter nations is, the US, Canada, Argentina, Brazil, Chile, Mexico, Venezuela and "Latin American countries". While glibc lists the US, Canada and Puerto Rico as the only Letter using territories.

Summary

Mapping locales to page size is done inconsistently. In OOo we should at least have one place that does it, not two. And reconcile the locales that have Letter as an appropriate default. We should also agree that when taking a locale setting to use to look up a default paper size that we try through LC_PAPER first, using _NL_PAPER_WIDTH/_NL_PAPER_HEIGHT (as shown here), and then fallback to mapping a locale territory to a default according to best fallback mapping below in order of LANGUAGE, LC_ALL, LC_MESSAGES, LANG, en_US

paperconf's own default of using Letter as a final fallback sucks as most people use A4, ideally paperconf could be convinced to use the same mechanism in the absence of a override setting.

Probable Best Fallback Mapping

All others, A4 (including Brazil, Argentina)

Pulling PageSize from LC_PAPER

#include <stdio.h>
#include <locale.h>
#include <langinfo.h>

#define NL_PAPER_GET(x)         \
  ((union { char *string; unsigned int word; })nl_langinfo(x)).word

int main(int argc,char **argv)
{
  int w, h;

  setlocale (LC_PAPER, "");
  w = NL_PAPER_GET (_NL_PAPER_WIDTH);
  h = NL_PAPER_GET (_NL_PAPER_HEIGHT);
  printf ("height: %d\nwidth: %d\n", h, w);
  return 0;
}

This gives dimensions in rounded mm, e.g. with Letter getting recorded as 216mm x 279mm, while the accurate size of Letter is 215.9 × 279.4. So a conversion to rounded to whole mm is required to test for recognized page sizes.

Notes on Legal, Folio, German Legal Fanfold and Long Bond Paper

The Philippines has a paper size called "Long Bond Paper", also known locally as "Legal" which is 8.5" x 13". The US Legal size is 8.5" x 14", causing confusion in the Philippines. 8.5" x 13" is called "German Legal Fanfold" in the PPD specification, but some people call that size "Folio". Unfortunately for the "Folio" term, in the PPD spec it is a different size than this (210mm x 220mm, i.e. 8.27" x 13"), and so is another ambivalent term probably best to be avoided.

Personal tools