Fix QString::toUcs4 returning invalid data when encountering stray surrogates

Code units 0xD800 .. 0xDFFF are not UCS-4, so we can't happily return them.
Instead, if we encounter a stray surrogate, replace it with 0xFFFD, which
is what Unicode recommends anyhow.

References:

§3.9 Unicode Encoding Forms

    D76: Unicode scalar value: Any Unicode code point except high-surrogate
    and low surrogate code points.

    As a result of this definition, the set of Unicode scalar values consists
    of the ranges 0 to D7FF_16 and E000_16 to 10FFFF_16, inclusive.

    [...]

    UTF-32 encoding form: The Unicode encoding form that assigns each Unicode
    scalar value to a single unsigned 32-bit code unit with the same numeric
    value as the Unicode scalar value.

§ C.2 Encoding Forms in ISO/IEC 10646

    UCS-4. UCS-4 stands for “Universal Character Set coded in 4 octets.” It is
    now treated simply as a synonym for UTF-32, and is considered the canonical
    form for representation of characters in 10646.

§ 3.9 Unicode Encoding Forms (Best Practices for Using U+FFFD)
and
§ 5.22 Best Practice for U+FFFD Substitution

    Whenever an unconvertible offset is reached during conversion of a code
    unit sequence:

    1. The maximal subpart at that offset should be replaced by a single
    U+FFFD.

    2. The conversion should proceed at the offset immediately after the
    maximal subpart.

    [...]

    Whenever an unconvertible offset is reached during conversion of a code
    unit sequence to Unicode:

    1. Find the longest code unit sequence that is the initial subsequence of
    some sequence that could be converted. If there is such a sequence, replace
    it with a single U+FFFD; otherwise replace a single code unit with a single
    U+FFFD.

    2. The conversion should proceed at the offset immediately after the
    subsequence which has been replaced.

[ChangeLog][QtCore][QString] QString::toUcs4 now does not return invalid
UCS-4 code units belonging to the surrogate range (U+D800 to U+DFFF)
when the QString contains malformed UTF-16 data. Instead, U+FFFD
is returned in place of the malformed subsequence.

Change-Id: I19d7af03e749fea680fd5d9635439bc9d56558a9
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
QUtfCodec: don't encode invalid UCS-4 codepoints

The code didn't check for malformed surrogate pairs. That means that

- high surrogates followed by *anything* were decoded as they formed
  a valid surrogate pair;
- stray low surrogates were returned as-is.

We can't return surrogate values in UCS-4, so properly detect these
cases and return U+FFFD instead.

[ChangeLog][QtCore][QTextCodec] Encoding a QString in UTF-32 will now
replace malformed UTF-16 subsequences in the string with the Unicode
replacement character (U+FFFD).

Change-Id: I5cd771d6aa21ffeff4dd9d9e5a7961cf692dc457
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
qmake WinRT: Default to x86 for lib path

If VCPROJ_ARCH is not recognized or unset, make "arch" default to x86,
or link won't find the libs.

Change-Id: If2cbda37a80c0fa43e1464775c036cebf10f931a
Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
WinRT: Use correct architecture values in manifests and vs

Using the same architecture value in VC Project and manifest
files only makes sense for x64. Instead of doing magic we
just set the correct values inside the mkspecs. VCPROJ_ARCH
is used for Visual Studio, while the manifests use
WINRT_MANIFEST.architecture.

WINRT_MANIFEST.architecture was added to x64 mkspecs for
consistency and phone mkspecs do not use WINRT_MANIFEST.architecture
so it does not have to be set there.

Change-Id: I009473104875b4add8c0530dc6f51177919e997b
Reviewed-by: Andrew Knight <andrew.knight@digia.com>
Optimize stringToCMap() usage

CMAP guarantees there is 1:1 mapping between the Unicode code points
array and the glyph indexes array, which means the QString length
always greater than or equal to a sufficient glyph indexes array length.

Simply add some asserts and improve the memory consumption
and the performance where possible.

Change-Id: I0bc8cdba5f86c1c0ba9e79c8d5f96cbe56ec463e
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
glxconvenience: Add a QT_XCB_FORCE_SOFTWARE_OPENGL environment variable.

The QT_XCB_FORCE_SOFTWARE_OPENGL environment variable is equivalent to
LIBGL_ALWAYS_SOFTWARE for Qt 5 applications only. This is most useful
with drivers that only support OpenGL 1. We need OpenGL 2, but the user
probably doesn't want LIBGL_ALWAYS_SOFTWARE in OpenGL 1 apps.

Together with
http://pkgs.fedoraproject.org/cgit/qt5-qtbase.git/tree/10-qt5-check-opengl2.sh
which goes into /etc/X11/xinit/xinitrc.d, it makes QML 2 just work on
old hardware that supports only OpenGL 1.x in hardware. The scriptlet
checks the glxinfo output for the OpenGL version and sets
QT_XCB_FORCE_SOFTWARE_OPENGL if the major version is < 2. (The scriptlet
requires xorg-x11-xinit and glx-utils.)

Tested on a Radeon 9200 SE (RV280) that supports only OpenGL 1.3 in
hardware.

Change-Id: Ief80d283820d6336052b8f390a0030ba9b687492
Reviewed-by: Jørgen Lind <jorgen.lind@digia.com>
QOpenGLTextureHelper: add a clarifying comment

Change-Id: Ia27fd6616b2259b3fbe71ea8737b270c323a1256
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
QOpenGLTextureHelper: fix 3D texture support on ES2

The code first tried to check for the GL_OES_texture_3D extension,
and if present it resolved the pointers to the gl*Tex*3DOES functions.
But then it overwrote those pointers by attempting to resolve the
Desktop GL gl*Tex*3D functions, thus making them unusable.

So, if the extension is found, don't overwrite the pointers.
If the extension is NOT found, keep the general behavior of still
trying to resolve those functions.

(That is going to fail, but refactoring the general behavior
belongs to a separate commit.)

Change-Id: Idaba122cf9500f136e3f79284d3c82284257036d
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
QOpenGLTexture: fix support for 1D textures

OpenGL ES 2 doesn't support 1D textures. So introduce a proper
feature flag and warn if we try to allocate one there.

Change-Id: I73cf58c1f257d2472564f45bff222231e39aca52
Reviewed-by: James Turner <james.turner@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
QOpenGLTextureHelper: explain why we use GetProcAddress on Windows / DesktopGL

In the future, we might want to refactor this code to inconditionally
use the common Desktop / ES2 subset (like the rest of Qt does),
and then resolve only the functions actually available at runtime.

For now, state why we're doing that on Windows.

Change-Id: Ic21035bcd88ddc1d9274fd90a146c2824d783b25
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Correctly manipulate tm_gmtoff the way qt_timezone() needs.

Follow-up to 91d3298: qt_timezone() expects the number of seconds west
of UTC, whereas tm_gmtoff returns the number of seconds east of UTC, and
contrary to the timezone variable it is not oblivious to DST.

We have to account for those two facts and make sure we return a value
compatible with what timezone would have.

Change-Id: Iacb9077f50d4c847ac09e5a7e952d0e4cd22da1b
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Windows: Fix broken debug statement in qwindowsglcontext.cpp.

Change-Id: Ifb26a7bb4461a88831459a17092944b068842d3e
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Fixed initialization of QPrintPreviewDialog's image resources for static builds.

[ChangeLog][QtPrintSupport][QPrintPreviewDialog] Fixed initialization of QPrintPreviewDialog's image resources for static builds.

Task-number: QTBUG-36561

Change-Id: Ibb725e7d0cd647b904371db2601161c756b99f53
Reviewed-by: Andy Shaw <andy.shaw@digia.com>
widgets/mainwindows/mainwindow example: Use mouse release event for dock title.

Task-number: QTBUG-36364

Change-Id: Ie3352c8e72a636aee2099ca3138eb0ac77425e7e
Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
Windows file dialog: Clean up thread manually.

Do not use deleteLater() to delete the thread.

Task-number: QTBUG-36357

Change-Id: Ie7c87b92a7c73d5fbac01d4951d387ee2facd05c
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Fallback to QWidget::grab() if QScreen::grabWindow() fails.

QScreen::grabWindow() is not always reliable because it grabs from the
framebuffer. (The window might then be covered by other windows, e.g.
"Stays on top"-Windows, popups etc).
If QScreen::grabWindow() fails we therefore fallback to
QWidget::grab(). This will not grab from the frame buffer, but it will
ask the widget to render itself (with its current state) to a pixmap
and return it.
QWidget::grab() should usually return the expected pixmap, and the
pixmap it gives is not subject to the state of the window manager.

This means that both QScreen::grabWindow() *and* QWidget::grab()
must produce an unexpected pixmap in order for the test to fail.

Change-Id: I276554155bb1e5b510d2a2d43628d91669464fe2
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
Make QStringBuilder use our qt_from_latin1 code (out-of-line)

Disassembly shows that the compiler does not perform the zero-expansion
by itself. It always opts to copy byte-by-byte, which is not very
performant.

Change-Id: I08780902461d9e3e6b7b54298f41d1eca61339c4
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Cocoa: Option handling.

Add qt_mac_resolveOption().

Support setting options using either an environment
variable or a QWindow property, with a default fallback
value. The options are resolved with precedence in
the mentioned order.

Adds options for the following:
NSView setWantsBestResolutionOPenGLSurface
NSVIew setWantsLayer
NSOpenGLContext NSOpenGLCPSurfaceOrder

The window properties use the _q_mac_camelCase format.
The environment variables use the QT_MAC_ALL_CAPS format.

Change-Id: I1978a02d62e107a2120d81ffdd0f7b32f7731644
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Compile.

Change-Id: Ib0e7e7aa2964835afda4055a5fe76abbd5db84e3
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Support --option in addition to -option for all builtin Qt commandline options.

In addition to being more common and consistent with QCommandLineParser, this
will make it possible to add the documentation for these options
in the QCommandLineParser-generated help output.

[ChangeLog][General] Builtin command-line options such as -reverse,
-session, -style etc. now all support double dash, e.g. --reverse,
--session, --style...

Change-Id: Ia2e22c854ccc6a9d7b863b1234317005bc822191
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>