Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 283828
Collapse All | Expand All

(-)a/src/IDocument.cxx (-14 / +52 lines)
Lines 27-36 Link Here
27
G_LOCK_DEFINE_STATIC (pageSearch);
27
G_LOCK_DEFINE_STATIC (pageSearch);
28
28
29
// Constants.
29
// Constants.
30
static const gdouble ZOOM_IN_FACTOR = 1.2;
30
static const gint MAX_ZOOM_STEPS = 19;
31
static const gdouble ZOOM_IN_MAX = 4.0;
31
static const gdouble ZOOM_FACTORS[MAX_ZOOM_STEPS] =
32
static const gdouble ZOOM_OUT_FACTOR = (1.0 / ZOOM_IN_FACTOR);
32
  { 0.1, 0.13, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.8,  // zoom out
33
static const gdouble ZOOM_OUT_MAX = 0.05409;
33
    1.0,                                            // default
34
    1.25, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 6.0, 8.0 }; // zoom in
34
static const guint CACHE_SIZE = 3;
35
static const guint CACHE_SIZE = 3;
35
36
36
/// This is the error domain that will be used to report Document's errors.
37
/// This is the error domain that will be used to report Document's errors.
Lines 148-153 Link Here
148
    m_Scale = 1.0f;
149
    m_Scale = 1.0f;
149
    m_Subject = NULL;
150
    m_Subject = NULL;
150
    m_Title = NULL;
151
    m_Title = NULL;
152
153
    m_zoomStepsPerformed = 9;
151
}
154
}
152
155
153
///
156
///
Lines 1216-1233 Link Here
1216
gboolean
1219
gboolean
1217
IDocument::canZoomIn (void)
1220
IDocument::canZoomIn (void)
1218
{
1221
{
1219
    return ( getZoom () * ZOOM_IN_FACTOR <= ZOOM_IN_MAX );
1222
    return getZoom () < ZOOM_FACTORS[MAX_ZOOM_STEPS-1];
1220
}
1223
}
1221
1224
1222
///
1225
///
1223
/// @brief Checks if is possible to zoom out.
1226
/// @brief Checks if is possible to zoom out.
1224
///
1227
///
1225
/// Checks if after zooming out the zoom level will be above the min level.
1228
/// Checks if after zooming out the zoom level will be below the min level.
1226
///
1229
///
1227
gboolean
1230
gboolean
1228
IDocument::canZoomOut (void)
1231
IDocument::canZoomOut (void)
1229
{
1232
{
1230
    return ( getZoom () * ZOOM_OUT_FACTOR >= ZOOM_OUT_MAX );
1233
    return getZoom () > ZOOM_FACTORS[0];
1231
}
1234
}
1232
1235
1233
///
1236
///
Lines 1251-1258 Link Here
1251
{
1254
{
1252
    if ( ABS (zoom - m_Scale) > 0.00001 )
1255
    if ( ABS (zoom - m_Scale) > 0.00001 )
1253
    {
1256
    {
1257
        gint idx;
1258
        gint lim = MAX_ZOOM_STEPS - 1;
1259
1254
        G_LOCK (JobRender);
1260
        G_LOCK (JobRender);
1255
        m_Scale = CLAMP (zoom, ZOOM_OUT_MAX, ZOOM_IN_MAX);
1261
        m_Scale = CLAMP (zoom, ZOOM_FACTORS[0], ZOOM_FACTORS[MAX_ZOOM_STEPS-1]);
1262
        for (idx = 1; idx < lim; ++idx)
1263
            if ( CLAMP ( m_Scale, ZOOM_FACTORS[idx-1], ZOOM_FACTORS[idx] )
1264
                 == m_Scale )
1265
                m_zoomStepsPerformed = idx - 1;
1256
        refreshCache ();
1266
        refreshCache ();
1257
        G_UNLOCK (JobRender);
1267
        G_UNLOCK (JobRender);
1258
        notifyPageZoomed ();
1268
        notifyPageZoomed ();
Lines 1270-1279 Link Here
1270
void
1280
void
1271
IDocument::zoomIn (void)
1281
IDocument::zoomIn (void)
1272
{
1282
{
1273
    if (canZoomIn ())
1283
    zoomInOutWrapper(0);
1274
    {
1275
        setZoom (getZoom () * ZOOM_IN_FACTOR);
1276
    }
1277
}
1284
}
1278
1285
1279
///
1286
///
Lines 1287-1296 Link Here
1287
void
1294
void
1288
IDocument::zoomOut (void)
1295
IDocument::zoomOut (void)
1289
{
1296
{
1290
    if (canZoomOut ())
1297
    zoomInOutWrapper(-1);
1298
}
1299
1300
///
1301
/// @brief Zooms In or Out
1302
///
1303
/// Common routine for zoomIn() and zoomOut() to exclude code duplication when
1304
/// making decision on value which should be added or to substracted to the
1305
/// current zoom level
1306
///
1307
/// @param zoomDirection Points whether to zoom in or zoom out the document.
1308
///
1309
/// @see zoomIn() zoomOut()
1310
///
1311
void
1312
IDocument::zoomInOutWrapper (gint zoomDirection)
1313
{
1314
  if ( (zoomDirection < 0) ? canZoomOut () : canZoomIn () )
1315
  {
1316
    gdouble currentScale = getZoom ();
1317
1318
    if ( ZOOM_FACTORS[m_zoomStepsPerformed] == currentScale )
1319
      m_zoomStepsPerformed += (zoomDirection == 0) ? 1 : -1;
1320
    else
1291
    {
1321
    {
1292
        setZoom (getZoom () * ZOOM_OUT_FACTOR);
1322
      gint idx;
1323
      gint lim = MAX_ZOOM_STEPS - 1;
1324
1325
      for ( idx = 1; idx < lim; ++idx )
1326
        if ( CLAMP ( currentScale, ZOOM_FACTORS[idx-1], ZOOM_FACTORS[idx] )
1327
             == currentScale )
1328
          m_zoomStepsPerformed = idx + zoomDirection;
1293
    }
1329
    }
1330
    setZoom ( ZOOM_FACTORS[m_zoomStepsPerformed] );
1331
  }
1294
}
1332
}
1295
1333
1296
///
1334
///
(-)a/src/IDocument.h (-1 / +6 lines)
Lines 357-363 Link Here
357
357
358
        protected:
358
        protected:
359
            static GQuark errorQuark;
359
            static GQuark errorQuark;
360
            
360
361
            IDocument (void);
361
            IDocument (void);
362
            void addPageToCache (gint pageNum);
362
            void addPageToCache (gint pageNum);
363
            PageCache *getCachedPage (gint pageNum);
363
            PageCache *getCachedPage (gint pageNum);
Lines 412-417 Link Here
412
            gchar *m_Subject;
412
            gchar *m_Subject;
413
            /// The document's title.
413
            /// The document's title.
414
            gchar *m_Title;
414
            gchar *m_Title;
415
416
    private:
417
            void zoomInOutWrapper (gint zoomDirection);
418
419
            gint m_zoomStepsPerformed;
415
    };
420
    };
416
}
421
}
417
422

Return to bug 283828